Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions ext/calendar/cal_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ PHP_FUNCTION(jdtounix)
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &uday) == FAILURE) {
RETURN_THROWS();
}
uday -= 2440588 /* J.D. of 1.1.1970 */;

if (uday < 0 || uday > ZEND_LONG_MAX / SECS_PER_DAY) { /* before beginning of unix epoch or greater than representable */
if (uday < 2440588 || (uday - 2440588) > (ZEND_LONG_MAX / SECS_PER_DAY)) { /* before beginning of unix epoch or greater than representable */
zend_value_error("jday must be between 2440588 and " ZEND_LONG_FMT, ZEND_LONG_MAX / SECS_PER_DAY + 2440588);
RETURN_THROWS();
}

uday -= 2440588 /* J.D. of 1.1.1970 */;

RETURN_LONG(uday * SECS_PER_DAY);
}
/* }}} */
21 changes: 21 additions & 0 deletions ext/calendar/tests/gh16231.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
GH-16231 (jdtounix argument overflow)
--EXTENSIONS--
calendar
--FILE--
<?php
try {
jdtounix(PHP_INT_MIN);
} catch (\ValueError $e) {
echo $e->getMessage() . PHP_EOL;
}

try {
jdtounix(240587);
} catch (\ValueError $e) {
echo $e->getMessage();
}
?>
--EXPECTF--
jday must be between 2440588 and %d
jday must be between 2440588 and %d
Loading