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: 2015-05-20 22:41 UTC
Votes:15
Avg. Score:4.4 ± 0.8
Reproduced:12 of 12 (100.0%)
Same Version:5 (41.7%)
Same OS:7 (58.3%)
From: sunchaojun at gmail dot com Assigned:
Status: Analyzed Package: Zip Related
PHP Version: 5.6.9 OS: windows
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

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>
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC