Bug #81488 [NEW]: ext/zip doesn't extract files with special names
| From: | cmb@php.net | Date: | Wed, 29 Sep 2021 12:38:10 +0000 |
| Subject: | Bug #81488 [NEW]: ext/zip doesn't extract files with special names | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-236917@lists.php.net to get a copy of this message | ||
From: cmb
Operating system: Windows
PHP version: 7.4Git-2021-09-29 (Git)
Package: Zip Related
Bug Type: Bug
Bug description:ext/zip doesn't extract files with special names
Description:
------------
On Windows, ZipArchive::extractTo() fails to extract files which
contain characters which are not allowed for NTFS file systems,
namely <|>*?":, and also filenames with trailing dots. Window's
built in extraction tool accepts a few of them (the exact
treatment is apparently version dependent), but if it works, the
special characters are replaced with an underscore. 7-zip replaces
all these characters with an underscore, and that actually appears
to be the desired behavior.
Note that files with a colon are actually extracted, but since a
colon marks an NTFS stream, it shows as filename with only the
leading part. This is undesireable, especially since PHP has only
partial support for NTFS streams (see bug #81339).
Test script:
---------------
<?php
$filenames = ["foo<bar1", "foo>bar2", "foo|bar3",
"foo*bar4",
"foo?bar5", "foo\"bar6", "foo:bar7", "foobar8."];
$zip = new ZipArchive();
$zip->open(__DIR__ . "/test.zip",
ZipArchive::CREATE|ZipArchive::OVERWRITE);
foreach ($filenames as $filename) {
$zip->addFromString($filename, "yada yada");
}
$zip->close();
mkdir(__DIR__ . "/extract");
$zip->open(__DIR__ . "/test.zip");
foreach ($filenames as $filename) {
$zip->extractTo(__DIR__ . "/extract", $filename);
}
?>
Expected result:
----------------
Array
(
[0] => .
[1] => ..
[2] => foo_bar1
[3] => foo_bar2
[4] => foo_bar3
[5] => foo_bar4
[6] => foo_bar5
[7] => foo_bar6
[8] => foo_bar7
[9] => foobar8_
)
Actual result:
--------------
Array
(
[0] => .
[1] => ..
[2] => foo
)
--
Edit bug report at https://bugs.php.net/bug.php?id=81488&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=81488&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=81488&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=81488&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=81488&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=81488&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=81488&r=support
Expected behavior: https://bugs.php.net/fix.php?id=81488&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=81488&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=81488&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=81488&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81488&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=81488&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=81488&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=81488&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=81488&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=81488&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=81488&r=mysqlcfg