Bug #50678 [Ana->Asn]: files extracted by ZipArchive class lost their original modified time

From: Date: Fri, 06 Mar 2020 14:09:33 +0000
Subject: Bug #50678 [Ana->Asn]: files extracted by ZipArchive class lost their original modified time
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225926@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=50678&edit=1 ID: 50678 Updated by: remi@php.net Reported by: sunchaojun at gmail dot com Summary: files extracted by ZipArchive class lost their original modified time -Status: Analyzed +Status: Assigned Type: Bug Package: Zip Related Operating System: windows PHP Version: 5.6.9 -Assigned To: +Assigned To: remi Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2015-05-20 22:41:54] 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> ------------------------------------------------------------------------ [2015-05-20 19:07:12] 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. ------------------------------------------------------------------------ [2014-08-06 11:40:13] michaeld at owl-online dot de sadly, it is still in there: php 5.5.11 win and php 5.3.4 linux ------------------------------------------------------------------------ [2010-06-15 22:32:02] 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. ------------------------------------------------------------------------ [2010-01-06 15:58:51] 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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=50678&edit=1

« previous php.bugs (#225926) next »