Skip to content

Commit 44c8b74

Browse files
committed
Fix #78241: touch() does not handle dates after 2038 in PHP 64-bit
`time_t` defaults to `_time64` (which is 64bit signed) even on x86, but `Int32x32To64()` truncates it to signed 32bit. We replace the macro with the "manual" calculation.
1 parent 32c6842 commit 44c8b74

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ PHP NEWS
2121
. Fixed #78189 (file cache strips last character of uname hash). (cmb)
2222
. Fixed #78202 (Opcache stats for cache hits are capped at 32bit NUM). (cmb)
2323

24+
- Standard:
25+
. Fixed #78241 (touch() does not handle dates after 2038 in PHP 64-bit). (cmb)
26+
2427
27 Jun 2019, PHP 7.2.20
2528

2629
- Core:

TSRM/tsrm_win32.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ static zend_always_inline void UnixTimeToFileTime(time_t t, LPFILETIME pft) /* {
804804
// Note that LONGLONG is a 64-bit value
805805
LONGLONG ll;
806806

807-
ll = Int32x32To64(t, 10000000) + 116444736000000000;
807+
ll = t * 10000000 + 116444736000000000;
808808
pft->dwLowDateTime = (DWORD)ll;
809809
pft->dwHighDateTime = ll >> 32;
810810
}

ext/standard/tests/file/bug78241.phpt

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Bug #78241 (touch() does not handle dates after 2038 in PHP 64-bit)
3+
--SKIPIF--
4+
<?php
5+
if (substr(PHP_OS, 0, 3) != 'WIN') die('skip this test is for Windows platforms only');
6+
if (PHP_INT_SIZE != 8) die('skip this test is for 64bit platforms only');
7+
?>
8+
--INI--
9+
date.timezone=UTC
10+
--FILE--
11+
<?php
12+
$filename = __DIR__ . '/bug78241.txt';
13+
for ($i = 2037; $i <= 2040; $i++) {
14+
$t = mktime(1, 1 , 1, 1, 1, $i);
15+
echo 'Date: '.date('D, d M Y H:i:s', $t), PHP_EOL;
16+
touch($filename, $t);
17+
clearstatcache(true, $filename);
18+
$file = filemtime($filename);
19+
echo 'File: '.date('D, d M Y H:i:s', $file), PHP_EOL, PHP_EOL;
20+
}
21+
?>
22+
--EXPECT--
23+
Date: Thu, 01 Jan 2037 01:01:01
24+
File: Thu, 01 Jan 2037 01:01:01
25+
26+
Date: Fri, 01 Jan 2038 01:01:01
27+
File: Fri, 01 Jan 2038 01:01:01
28+
29+
Date: Sat, 01 Jan 2039 01:01:01
30+
File: Sat, 01 Jan 2039 01:01:01
31+
32+
Date: Sun, 01 Jan 2040 01:01:01
33+
File: Sun, 01 Jan 2040 01:01:01

0 commit comments

Comments
 (0)