Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ext/calendar/easter.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ static void _cal_easter(INTERNAL_FUNCTION_PARAMETERS, bool gm)
}
}

if (year < 0 || year > (ZEND_LONG_MAX - 1)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The computation dom = (year + (year/4) - (year/100) + (year/400)) % 7 can still overflow.
Also, year 0 does not exist.

zend_argument_value_error(1, "must be between 0 and " ZEND_LONG_FMT, (ZEND_LONG_MAX - 1));
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();
Expand Down
26 changes: 26 additions & 0 deletions ext/calendar/tests/gh16228.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
GH-16228 (easter_days, Overflow on year argument)
--EXTENSIONS--
calendar
--FILE--
<?php
try {
easter_days(PHP_INT_MAX, 0);
} catch (\ValueError $e) {
echo $e->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 0 and %d
easter_days(): Argument #1 ($year) must be between 0 and %d
easter_date(): Argument #1 ($year) must be between 0 and %d
Loading