php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50678 files extracted by ZipArchive class lost their original modified time
Submitted: 2010-01-06 15:58 UTC Modified: 2020-03-06 14:09 UTC
Votes:21
Avg. Score:4.3 ± 0.9
Reproduced:15 of 15 (100.0%)
Same Version:6 (40.0%)
Same OS:10 (66.7%)
From: sunchaojun at gmail dot com Assigned: remi (profile)
Status: Closed Package: Zip Related
PHP Version: 5.6.9 OS: windows
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: sunchaojun at gmail dot com
New email:
PHP Version: OS:

 

 [2010-01-06 15:58 UTC] sunchaojun at gmail dot com
Description:
------------
After I extract a zip file via ZipArchive class in my php codes, I found that the creation time, modified time and lastaccess time of the files extracted have been set to the time at that it was being extracted.

Reproduce code:
---------------
---
From manual page: class.ziparchive
---
$zip = new ZipArchive();
if ($zip->open('test.zip')) {
   zip->extractTo
   zip.close()
}

Expected result:
----------------
A extracted files has the same creation time, modified time and lastaccess time with its oringinal copy.

Actual result:
--------------
The creation time, modified time and lastaccess time of a extracted file has been reset when extracting.

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-15 22:32 UTC] hardcorevenom at gmx dot de
Server:
PHP Version 5.2.13
Apache/2.2.3 (Scientific Linux)

ZipArchive::extractTo("dir") sets the dates of all extracted files to the current time. The original "mdate" stored in the zip archive is not restored as expected.
AFAIK last access and creation time is not stored in a zip file, only last modified. So access and creation time is currently set correctly.
 [2014-08-06 11:40 UTC] michaeld at owl-online dot de
sadly, it is still in there:  php 5.5.11 win and php 5.3.4 linux
 [2015-05-20 19:07 UTC] cmb@php.net
-Status: Open +Status: Verified -PHP Version: 5.2.12 +PHP Version: 5.6.9
 [2015-05-20 19:07 UTC] cmb@php.net
Verified for PHP 5.6.9.

> AFAIK last access and creation time is not stored in a zip file,
> [...]

The creation time can be stored in a ZIP file, but ZipArchive
doesn't do that.
 [2015-05-20 22:41 UTC] cmb@php.net
-Status: Verified +Status: Analyzed
 [2015-05-20 22:41 UTC] cmb@php.net
I have to correct myself. According to the PKWARE ZIP file format
specification [1], the only timestamp that is generally available
for files in an archive is the mtime. ctime and atime are only
supported for some host systems and available in extra fields,
which don't seem to be supported by libzip[2] at all.

To set the stored mtime when files are extracted, it seems to be
sufficient to retrieve it via zip_stat_index() and to touch the
files after extraction in php_zip_extract_file().

[1] <https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT>
[2] <http://www.nih.at/libzip/zip_stat.html>
 [2020-03-06 14:09 UTC] remi@php.net
-Status: Analyzed +Status: Assigned -Assigned To: +Assigned To: remi
 [2020-03-06 14:10 UTC] remi@php.net
The following pull request has been associated:

Patch Name: Fix #50678 files extracted by ZipArchive class lost their original mo…
On GitHub:  https://github.com/php/php-src/pull/5244
Patch:      https://github.com/php/php-src/pull/5244.patch
 [2020-03-09 06:09 UTC] remi@php.net
Automatic comment on behalf of remi
Revision: http://git.php.net/?p=php-src.git;a=commit;h=ed998f8a0dc727be21b3a4b10841c10dbafe5e6d
Log: Fix #50678 files extracted by ZipArchive class lost their original modified time
 [2020-03-09 06:09 UTC] remi@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC