Bug #81488 [Asn]: ext/zip doesn't extract files with special names

From: Date: Wed, 29 Sep 2021 13:58:05 +0000
Subject: Bug #81488 [Asn]: ext/zip doesn't extract files with special names
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-236919@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81488&edit=1 ID: 81488 Updated by: cmb@php.net Reported by: cmb@php.net Summary: ext/zip doesn't extract files with special names Status: Assigned Type: Bug Package: Zip Related Operating System: Windows PHP Version: 7.4Git-2021-09-29 (Git) Assigned To: cmb Block user comment: N Private report: N New Comment: > 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"] Previous Comments: ------------------------------------------------------------------------ [2021-09-29 12:55:42] remi@php.net @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] cmb@php.net 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

« previous php.bugs (#236919) next »