Skip to content

Fix GH-10766: PharData archive created with Phar::Zip format does not keep files metadata (datetime) #10769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions ext/phar/tests/zip/gh10766.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
GH-10766 (PharData archive created with Phar::Zip format does not keep files metadata (datetime))
--EXTENSIONS--
phar
zip
--INI--
phar.readonly=0
--FILE--
<?php
$phar = new PharData(__DIR__ . '/gh10766.zip', 0, null, Phar::ZIP);
$phar->addFromString('name', 'contents');
unset($phar);

// Re-read from disk, but using the zip extension because the phar bug will not make it possible
// to use their timestamp methods.
$zip = new ZipArchive();
$zip->open(__DIR__ . '/gh10766.zip');
var_dump($zip->statName('name')['mtime'] > 315529200 /* earliest possible zip timestamp */);
$zip->close();
?>
--CLEAN--
<?php
unlink(__DIR__ . '/gh10766.zip');
?>
--EXPECT--
bool(true)
3 changes: 2 additions & 1 deletion ext/phar/zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ static void phar_zip_u2d_time(time_t time, char *dtime, char *ddate) /* {{{ */
struct tm *tm, tmbuf;

tm = php_localtime_r(&time, &tmbuf);
if (tm->tm_year >= 1980) {
/* Note: tm_year is the year - 1900 */
if (tm->tm_year >= 80) {
cdate = ((tm->tm_year+1900-1980)<<9) + ((tm->tm_mon+1)<<5) + tm->tm_mday;
ctime = ((tm->tm_hour)<<11) + ((tm->tm_min)<<5) + ((tm->tm_sec)>>1);
} else {
Expand Down