mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Fix GH-10766: PharData archive created with Phar::Zip format does not keep files metadata (datetime)
Due to an incorrect check, the datetime was never actually set. To test this we need to write the file using phar, but read the file using a different method to not get a cached, or a value that's been transformed twice and is therefore accidentally correct. Closes GH-10769
This commit is contained in:
parent
574a7e7ef8
commit
e633be3e87
3 changed files with 32 additions and 1 deletions
4
NEWS
4
NEWS
|
@ -12,6 +12,10 @@ PHP NEWS
|
|||
- Opcache:
|
||||
. Fixed build for macOS to cater with pkg-config settings. (David Carlier)
|
||||
|
||||
- Phar:
|
||||
. Fixed bug GH-10766 (PharData archive created with Phar::Zip format does
|
||||
not keep files metadata (datetime)). (nielsdos)
|
||||
|
||||
16 Mar 2023, PHP 8.1.17
|
||||
|
||||
- Core:
|
||||
|
|
26
ext/phar/tests/zip/gh10766.phpt
Normal file
26
ext/phar/tests/zip/gh10766.phpt
Normal file
|
@ -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)
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue