diff --git a/ext/calendar/cal_unix.c b/ext/calendar/cal_unix.c index da6a184e6c17a..d364079bd0474 100644 --- a/ext/calendar/cal_unix.c +++ b/ext/calendar/cal_unix.c @@ -23,6 +23,8 @@ #include "sdncal.h" #include +#define SECS_PER_DAY (24 * 3600) + /* {{{ proto int unixtojd([int timestamp]) Convert UNIX timestamp to Julian Day */ PHP_FUNCTION(unixtojd) @@ -62,11 +64,11 @@ PHP_FUNCTION(jdtounix) } uday -= 2440588 /* J.D. of 1.1.1970 */; - if (uday < 0 || uday > 24755) { /* before beginning of unix epoch or behind end of unix epoch */ + if (uday < 0 || uday > ZEND_LONG_MAX / SECS_PER_DAY) { /* before beginning of unix epoch or greater than representable */ RETURN_FALSE; } - RETURN_LONG(uday * 24 * 3600); + RETURN_LONG(uday * SECS_PER_DAY); } /* }}} */ diff --git a/ext/calendar/tests/bug80185.phpt b/ext/calendar/tests/bug80185.phpt new file mode 100644 index 0000000000000..cd9ddb7d2979e --- /dev/null +++ b/ext/calendar/tests/bug80185.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #80185 (jdtounix() fails after 2037) +--SKIPIF-- + +--FILE-- + +--EXPECT-- +int(2170713600) +int(9223372036854720000) +bool(false) diff --git a/ext/calendar/tests/bug80185_32bit.phpt b/ext/calendar/tests/bug80185_32bit.phpt new file mode 100644 index 0000000000000..95ee050171eb9 --- /dev/null +++ b/ext/calendar/tests/bug80185_32bit.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #80185 (jdtounix() fails after 2037) +--SKIPIF-- + +--FILE-- + +--EXPECT-- +bool(false) +int(2147472000) +bool(false)