diff --git a/ext/calendar/easter.c b/ext/calendar/easter.c index c319abd17fef..2832d0bdefe0 100644 --- a/ext/calendar/easter.c +++ b/ext/calendar/easter.c @@ -28,6 +28,7 @@ static void _cal_easter(INTERNAL_FUNCTION_PARAMETERS, bool gm) struct tm te; zend_long year, golden, solar, lunar, pfm, dom, tmp, easter, result; zend_long method = CAL_EASTER_DEFAULT; + const zend_long max_year = ZEND_LONG_MAX / 1.25; bool year_is_null = 1; if (zend_parse_parameters(ZEND_NUM_ARGS(), @@ -48,6 +49,11 @@ static void _cal_easter(INTERNAL_FUNCTION_PARAMETERS, bool gm) } } + if (year <= 0 || year > max_year) { + zend_argument_value_error(1, "must be between 1 and " ZEND_LONG_FMT, max_year); + RETURN_THROWS(); + } + if (gm && (year<1970 || year>2037)) { /* out of range for timestamps */ zend_argument_value_error(1, "must be between 1970 and 2037 (inclusive)"); RETURN_THROWS(); diff --git a/ext/calendar/tests/gh16228.phpt b/ext/calendar/tests/gh16228.phpt new file mode 100644 index 000000000000..9ce80688195b --- /dev/null +++ b/ext/calendar/tests/gh16228.phpt @@ -0,0 +1,26 @@ +--TEST-- +GH-16228 (easter_days, Overflow on year argument) +--EXTENSIONS-- +calendar +--FILE-- +getMessage() . PHP_EOL; +} +try { + easter_days(-1, 0); +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; +} +try { + easter_date(PHP_INT_MAX, 0); +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; +} +?> +--EXPECTF-- +easter_days(): Argument #1 ($year) must be between 1 and %d +easter_days(): Argument #1 ($year) must be between 1 and %d +easter_date(): Argument #1 ($year) must be between 1 and %d