From: Christoph M. Becker Date: Wed, 7 Oct 2020 11:28:22 +0000 (+0200) Subject: Merge branch 'PHP-7.4' into master X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=92d0a101508f535b98636509cb8695823aeeb926;p=php Merge branch 'PHP-7.4' into master * PHP-7.4: Fix #80185: jdtounix() fails after 2037 --- 92d0a101508f535b98636509cb8695823aeeb926 diff --cc ext/calendar/cal_unix.c index 55d67823ff,864499c9cc..f1740c86af --- a/ext/calendar/cal_unix.c +++ b/ext/calendar/cal_unix.c @@@ -21,19 -23,21 +21,21 @@@ #include "sdncal.h" #include + #define SECS_PER_DAY (24 * 3600) + -/* {{{ proto int unixtojd([int timestamp]) - Convert UNIX timestamp to Julian Day */ +/* {{{ Convert UNIX timestamp to Julian Day */ PHP_FUNCTION(unixtojd) { - time_t ts = 0; + time_t ts; zend_long tl = 0; + zend_bool tl_is_null = 1; struct tm *ta, tmbuf; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &tl) == FAILURE) { - return; + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!", &tl, &tl_is_null) == FAILURE) { + RETURN_THROWS(); } - if (!tl) { + if (tl_is_null) { ts = time(NULL); } else if (tl >= 0) { ts = (time_t) tl; @@@ -60,11 -64,10 +62,11 @@@ PHP_FUNCTION(jdtounix } uday -= 2440588 /* J.D. of 1.1.1970 */; - if (uday < 0 || uday > 24755) { - zend_value_error("jday must be within the Unix epoch"); + if (uday < 0 || uday > ZEND_LONG_MAX / SECS_PER_DAY) { /* before beginning of unix epoch or greater than representable */ - RETURN_FALSE; ++ zend_value_error("jday must be between 2440588 and " ZEND_LONG_FMT, ZEND_LONG_MAX / SECS_PER_DAY + 2440588); + RETURN_THROWS(); } - RETURN_LONG(uday * 24 * 3600); + RETURN_LONG(uday * SECS_PER_DAY); } /* }}} */ diff --cc ext/calendar/tests/bug80185.phpt index 0000000000,cd9ddb7d29..eab5cf1c4b mode 000000,100644..100644 --- a/ext/calendar/tests/bug80185.phpt +++ b/ext/calendar/tests/bug80185.phpt @@@ -1,0 -1,17 +1,21 @@@ + --TEST-- + Bug #80185 (jdtounix() fails after 2037) + --SKIPIF-- + + --FILE-- + getMessage(), PHP_EOL; ++} + ?> + --EXPECT-- + int(2170713600) + int(9223372036854720000) -bool(false) ++jday must be between 2440588 and 106751993607888 diff --cc ext/calendar/tests/bug80185_32bit.phpt index 0000000000,95ee050171..98a1bea2a3 mode 000000,100644..100644 --- a/ext/calendar/tests/bug80185_32bit.phpt +++ b/ext/calendar/tests/bug80185_32bit.phpt @@@ -1,0 -1,17 +1,25 @@@ + --TEST-- + Bug #80185 (jdtounix() fails after 2037) + --SKIPIF-- + + --FILE-- + getMessage(), PHP_EOL; ++} + var_dump(jdtounix(PHP_INT_MAX / 86400 + 2440588)); -var_dump(jdtounix(PHP_INT_MAX / 86400 + 2440589)); ++try { ++ var_dump(jdtounix(PHP_INT_MAX / 86400 + 2440589)); ++} catch (ValueError $ex) { ++ echo $ex->getMessage(), PHP_EOL; ++} + ?> + --EXPECT-- -bool(false) ++jday must be between 2440588 and 2465443 + int(2147472000) -bool(false) ++jday must be between 2440588 and 2465443 diff --cc ext/calendar/tests/jdtounix_error1.phpt index e47cced1b1,5d4ea38834..de266ac6a2 --- a/ext/calendar/tests/jdtounix_error1.phpt +++ b/ext/calendar/tests/jdtounix_error1.phpt @@@ -8,11 -8,7 +8,11 @@@ date.timezone=UT --FILE-- getMessage(), PHP_EOL; +} ?> --EXPECT-- - jday must be within the Unix epoch -bool(false) ++jday must be between 2440588 and 2465443