Skip to content

Commit d8294f2

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

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ PHP NEWS
1212
- Opcache:
1313
. Fixed build for macOS to cater with pkg-config settings. (David Carlier)
1414

15+
- Phar:
16+
. Fixed bug GH-10766 (PharData archive created with Phar::Zip format does
17+
not keep files metadata (datetime)). (nielsdos)
18+
1519
16 Mar 2023, PHP 8.2.4
1620

1721
- Core:

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)