Bug #72258 [NEW]: ZipArchive converts filenames to unrecoverableform

From: Date: Tue, 24 May 2016 04:55:18 +0000
Subject: Bug #72258 [NEW]: ZipArchive converts filenames to unrecoverableform
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-201250@lists.php.net to get a copy of this message
From:             speller at yandex dot ru
Operating system: Windows 7
PHP version:      5.6.21
Package:          Zip Related
Bug Type:         Bug
Bug description:ZipArchive converts filenames to unrecoverableform

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 bug report at https://bugs.php.net/bug.php?id=72258&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=72258&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=72258&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=72258&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=72258&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=72258&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=72258&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=72258&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=72258&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=72258&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=72258&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=72258&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=72258&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=72258&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72258&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=72258&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=72258&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=72258&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72258&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=72258&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=72258&r=mysqlcfg



Thread (4 messages)

« previous php.bugs (#201250) next »