Skip to content

Commit

Permalink
Fix #78241: touch() does not handle dates after 2038 in PHP 64-bit
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
cmb69 committed Jul 3, 2019
1 parent 32c6842 commit 44c8b74
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ PHP NEWS
. Fixed #78189 (file cache strips last character of uname hash). (cmb)
. Fixed #78202 (Opcache stats for cache hits are capped at 32bit NUM). (cmb)

- Standard:
. Fixed #78241 (touch() does not handle dates after 2038 in PHP 64-bit). (cmb)

27 Jun 2019, PHP 7.2.20

- Core:
Expand Down
2 changes: 1 addition & 1 deletion TSRM/tsrm_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ static zend_always_inline void UnixTimeToFileTime(time_t t, LPFILETIME pft) /* {
// Note that LONGLONG is a 64-bit value
LONGLONG ll;

ll = Int32x32To64(t, 10000000) + 116444736000000000;
ll = t * 10000000 + 116444736000000000;
pft->dwLowDateTime = (DWORD)ll;
pft->dwHighDateTime = ll >> 32;
}
Expand Down
33 changes: 33 additions & 0 deletions ext/standard/tests/file/bug78241.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--TEST--
Bug #78241 (touch() does not handle dates after 2038 in PHP 64-bit)
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) != 'WIN') die('skip this test is for Windows platforms only');
if (PHP_INT_SIZE != 8) die('skip this test is for 64bit platforms only');
?>
--INI--
date.timezone=UTC
--FILE--
<?php
$filename = __DIR__ . '/bug78241.txt';
for ($i = 2037; $i <= 2040; $i++) {
$t = mktime(1, 1 , 1, 1, 1, $i);
echo 'Date: '.date('D, d M Y H:i:s', $t), PHP_EOL;
touch($filename, $t);
clearstatcache(true, $filename);
$file = filemtime($filename);
echo 'File: '.date('D, d M Y H:i:s', $file), PHP_EOL, PHP_EOL;
}
?>
--EXPECT--
Date: Thu, 01 Jan 2037 01:01:01
File: Thu, 01 Jan 2037 01:01:01

Date: Fri, 01 Jan 2038 01:01:01
File: Fri, 01 Jan 2038 01:01:01

Date: Sat, 01 Jan 2039 01:01:01
File: Sat, 01 Jan 2039 01:01:01

Date: Sun, 01 Jan 2040 01:01:01
File: Sun, 01 Jan 2040 01:01:01

0 comments on commit 44c8b74

Please sign in to comment.