Skip to content

Commit 9dddfbe

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #80185: jdtounix() fails after 2037
2 parents 3b7c8bb + e857dfa commit 9dddfbe

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ PHP NEWS
99
(cmb)
1010
. Fixed bug #80126 (Covariant return types failing compilation). (Nikita)
1111

12+
- Calendar:
13+
. Fixed bug #80185 (jdtounix() fails after 2037). (cmb)
14+
1215
- MySQLnd:
1316
. Fixed bug #80115 (mysqlnd.debug doesn't recognize absolute paths with
1417
slashes). (cmb)

ext/calendar/cal_unix.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include "sdncal.h"
2424
#include <time.h>
2525

26+
#define SECS_PER_DAY (24 * 3600)
27+
2628
/* {{{ proto int unixtojd([int timestamp])
2729
Convert UNIX timestamp to Julian Day */
2830
PHP_FUNCTION(unixtojd)
@@ -62,10 +64,10 @@ PHP_FUNCTION(jdtounix)
6264
}
6365
uday -= 2440588 /* J.D. of 1.1.1970 */;
6466

65-
if (uday < 0 || uday > 24755) { /* before beginning of unix epoch or behind end of unix epoch */
67+
if (uday < 0 || uday > ZEND_LONG_MAX / SECS_PER_DAY) { /* before beginning of unix epoch or greater than representable */
6668
RETURN_FALSE;
6769
}
6870

69-
RETURN_LONG(uday * 24 * 3600);
71+
RETURN_LONG(uday * SECS_PER_DAY);
7072
}
7173
/* }}} */

ext/calendar/tests/bug80185.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Bug #80185 (jdtounix() fails after 2037)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('calendar')) die('skip ext/calendar required');
6+
if (PHP_INT_SIZE != 8) die("skip for 64bit platforms only");
7+
?>
8+
--FILE--
9+
<?php
10+
var_dump(jdtounix(2465712));
11+
var_dump(jdtounix(PHP_INT_MAX / 86400 + 2440588));
12+
var_dump(jdtounix(PHP_INT_MAX / 86400 + 2440589));
13+
?>
14+
--EXPECT--
15+
int(2170713600)
16+
int(9223372036854720000)
17+
bool(false)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Bug #80185 (jdtounix() fails after 2037)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('calendar')) die('skip ext/calendar required');
6+
if (PHP_INT_SIZE != 4) die("skip for 32bit platforms only");
7+
?>
8+
--FILE--
9+
<?php
10+
var_dump(jdtounix(2465712));
11+
var_dump(jdtounix(PHP_INT_MAX / 86400 + 2440588));
12+
var_dump(jdtounix(PHP_INT_MAX / 86400 + 2440589));
13+
?>
14+
--EXPECT--
15+
bool(false)
16+
int(2147472000)
17+
bool(false)

0 commit comments

Comments
 (0)