Skip to content

Commit 43c71df

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Fix GH-10766: PharData archive created with Phar::Zip format does not keep files metadata (datetime)
2 parents 86ec0bc + d8294f2 commit 43c71df

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

ext/phar/tests/zip/gh10766.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
GH-10766 (PharData archive created with Phar::Zip format does not keep files metadata (datetime))
3+
--EXTENSIONS--
4+
phar
5+
zip
6+
--INI--
7+
phar.readonly=0
8+
--FILE--
9+
<?php
10+
$phar = new PharData(__DIR__ . '/gh10766.zip', 0, null, Phar::ZIP);
11+
$phar->addFromString('name', 'contents');
12+
unset($phar);
13+
14+
// Re-read from disk, but using the zip extension because the phar bug will not make it possible
15+
// to use their timestamp methods.
16+
$zip = new ZipArchive();
17+
$zip->open(__DIR__ . '/gh10766.zip');
18+
var_dump($zip->statName('name')['mtime'] > 315529200 /* earliest possible zip timestamp */);
19+
$zip->close();
20+
?>
21+
--CLEAN--
22+
<?php
23+
unlink(__DIR__ . '/gh10766.zip');
24+
?>
25+
--EXPECT--
26+
bool(true)

ext/phar/zip.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ static void phar_zip_u2d_time(time_t time, char *dtime, char *ddate) /* {{{ */
147147
struct tm *tm, tmbuf;
148148

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

0 commit comments

Comments
 (0)