php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78241 touch() does not handle dates after 2038 in PHP 64-bit
Submitted: 2019-07-02 18:09 UTC Modified: 2019-07-03 08:05 UTC
From: goozak at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Filesystem function related
PHP Version: 7.2.20RC3 OS: Windows 10
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: goozak at gmail dot com
New email:
PHP Version: OS:

 

 [2019-07-02 18:09 UTC] goozak at gmail dot com
Description:
------------
On PHP 7.2.20 64-bit, on Windows, touch() cannot set a file's date to a date after 2038. filemtime() will read such a file's date fine (date was set with an external tool).

Test script:
---------------
<pre><?php
$filename = 'C:\\Test\\TestFile.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).'<br>';
  touch($filename, $t);
  clearstatcache(true, $filename);
  $file = filemtime($filename);
  // This will be wrong for 2039 and 2040
  echo 'File: '.date('D, d M Y H:i:s', $file).'<br><br>';
}
?></pre>


Expected result:
----------------
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


Actual result:
--------------
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: Tue, 25 Nov 1902 18:32:45 <--- Wrong!

Date: Sun, 01 Jan 2040 01:01:01
File: Wed, 25 Nov 1903 18:32:45 <--- Wrong!


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-07-02 18:40 UTC] requinix@php.net
Same for 7.3. However 7.4alpha2 shows 22 Apr 60358...
 [2019-07-03 08:04 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=44c8b7414ce96038017edc2fd827f8250669a62a
Log: Fix #78241: touch() does not handle dates after 2038 in PHP 64-bit
 [2019-07-03 08:04 UTC] cmb@php.net
-Status: Open +Status: Closed
 [2019-07-03 08:05 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 11:01:29 2024 UTC