Doc #72258 [Ana->Csd]: ZipArchive converts filenames to unrecoverable form

From: Date: Tue, 19 Jul 2016 09:59:16 +0000
Subject: Doc #72258 [Ana->Csd]: ZipArchive converts filenames to unrecoverable form
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-13737@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72258&edit=1 ID: 72258 Updated by: ab@php.net Reported by: speller at yandex dot ru Summary: ZipArchive converts filenames to unrecoverable form -Status: Analyzed +Status: Closed Type: Documentation Problem Package: Zip Related Operating System: Windows 7 PHP Version: 5.6.21 -Assigned To: +Assigned To: ab Block user comment: N Private report: N New Comment: The documentation is now online, thanks Remi. Previous Comments: ------------------------------------------------------------------------ [2016-05-30 12:06:50] ab@php.net As of next 7.0, it'll be possible to use flag constants for filename encoding (see UPGRADING). In this case, ZipArchive::FL_ENC_RAW is useful. Thus, turning this into a doc issue. Thanks. ------------------------------------------------------------------------ [2016-05-25 18:52:08] ab@php.net Thanks for the report. The issue is about the discrepancy between the libzip versions used, not about PHP itself. The libzip moves evermore to UTF-8 making in default in various areas. The version used in PHP 5.6 explicitly requires the flags that were missed to be synchronized with the new libzip version. @speller, a workaround for now: $fileNameInArc = $zip->getNameIndex($i, 64); Otherwise the filename will be converted to UTF-8 using the current ACP, which can yield quite weird results. Thanks. ------------------------------------------------------------------------ [2016-05-24 11:49:21] speller at yandex dot ru The bug #72200 is about creating new archive and adding files to it. This issue is about reading archive. Also, I point your view to the fact that two versions of the official PHP binary produce *different* results. ------------------------------------------------------------------------ [2016-05-24 10:29:34] cmb@php.net That might be related to bug #72200. ------------------------------------------------------------------------ [2016-05-24 04:55:09] speller at yandex dot ru Description: ------------ I have a test zip archive with only one dir named (АБВГД) created under Windows with Russian locale. If you will look to the zip file in HEX mode you will see the dir name "80 81 82 83 84 2F" (АБВГД/), five 1-byte chars + slash. Under PHP 5.4 the ZipArchive::getNameIndex function onthis archive returned the name as is - in cp866 encoding. So I was able to convert it to correct text. After upgrading to PHP 5.6 this function returns names transcoded to something unrecoverable. The result of the ZipArchive::getNameIndex transcoded by PHP internally to five *2-bytes* chars + slash! I tried to set default_encoding ini setting, but without success. So I can not work properly with such archives at all. Run test script under precompiled PHP 5.4 from the php.net and the same PHP 5.6 and you will see different results: Test script: --------------- <? echo setlocale(LC_ALL, 'Russian_Russia.20866'), "\n"; ini_set('default_charset', 'cp866'); $zip = new \ZipArchive(); $res = $zip->open('test.zip'); if ($res !== true) { echo 'Error opening: ' . $res; die(); } for ($i = 0; $i < $zip->numFiles; $i++) { $stat = $zip->statIndex($i); $fileNameInArc = $zip->getNameIndex($i); echo $fileNameInArc, "\n"; echo iconv('cp866', 'utf-8', $fileNameInArc), "\n"; } Expected result: ---------------- php.5.4.32\php test.php Russian_Russia.20866 АБВГД/ ╨Р╨С╨Т╨У╨Ф/ Actual result: -------------- php.5.6.21\php test.php Russian_Russia.20866 ├З├╝├й├в├д/ тФЬ╨ЧтФЬтХЭтФЬ╨╣тФЬ╨▓тФЬ╨┤/ ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=72258&edit=1

« previous php.doc.bugs (#13737) next »