Edit report at https://bugs.php.net/bug.php?id=81488&edit=1
ID: 81488
Updated by: [email protected]
Reported by: [email protected]
Summary: ext/zip doesn't extract files with special names
-Status: Assigned
+Status: Open
-Type: Bug
+Type: Documentation Problem
Package: Zip Related
Operating System: Windows
PHP Version: 7.4Git-2021-09-29 (Git)
-Assigned To: cmb
+Assigned To:
Block user comment: N
Private report: N
New Comment:
After some short discussion on the PR, I think it's better to
leave this as is, and to document the behavior.
Previous Comments:
------------------------------------------------------------------------
[2021-09-29 13:58:05] [email protected]
> If this is a general issue on Windows, seems better to discuss
> this with libzip upstream and fix it there (if wanted)
Hmm, that would also mean that the modified names are shown when
accessing them (e.g. ZipArchive::getNameIndex()). Might actually
be better. I filed <https://github.com/nih-at/libzip/issues/263>.
> And, BTW, what will happen with :
> $filenames = ["foo<bar", "foo>bar", "foo|bar", "foo*bar", "foo?bar", "foo\"bar", "foo:bar", "foo_bar"];
The last one wins. But that already happens with e.g.
$filenames = ["/foobar", "./foobar", "foobar"]
------------------------------------------------------------------------
[2021-09-29 12:55:42] [email protected]
@cmb I'm a bit reluctant to fix this in the ext/zip side.
If this is a general issue on Windows, seems better to discuss this with libzip upstream and fix it there (if wanted)
And, BTW, what will happen with :
$filenames = ["foo<bar", "foo>bar", "foo|bar", "foo*bar", "foo?bar", "foo\"bar", "foo:bar", "foo_bar"];
------------------------------------------------------------------------
[2021-09-29 12:38:10] [email protected]
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 this bug report at https://bugs.php.net/bug.php?id=81488&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.