Bug #69279 [NEW]: Compressed ZIP Phar extractTo() creates garbage files

From: Date: Mon, 23 Mar 2015 01:32:29 +0000
Subject: Bug #69279 [NEW]: Compressed ZIP Phar extractTo() creates garbage files
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191535@lists.php.net to get a copy of this message
From: mario at include-once dot org Operating system: Linux/3.13/amd64 PHP version: 5.6.7 Package: PHAR related Bug Type: Bug Bug description:Compressed ZIP Phar extractTo() creates garbage files Description: ------------ See also #50797 - "PHAR fails to extract ZIP archives, but TAR is ok", which seems to document the same issue. Phar::extractTo() creates compressed/garbage output. Extracted files match the recorded file sizes. But they'll contain some binary content instead of the actual and decompressed file contents. It seems extractTo slices out raw ZIP archive contents, 18 bytes after the stored filename of the local PK file header. This behaviour isn't specific to 5.6.x, happened throughout 5.3, 5.4 and 5.5 too. (Example run against 5.6.6-1~dotdeb.1/ZTS/amd64.) An interesting workaround btw, is to use the phar:// streamwrapper prior. If a compressed file from the ZIP is accessed (per file_get_contents("phar://test.phar.zip/phar-test.txt") beforehand), then Phar::extractTo can reproduce the original file content. Test script: --------------- define('PHAR_FNAME', "test.phar.zip"); define('SAMPLE_FN', "phar-test.txt"); define('SAMPLE_TXT', "Sample content.\n"); // Create ZIP+GZ-Phar $w = new Phar(PHAR_FNAME); $w[SAMPLE_FN] = SAMPLE_TXT; $w->compressFiles(Phar::GZ); // Open anew $r = new Phar(PHAR_FNAME); assert($r[SAMPLE_FN]->isCompressed()); // Extract to file and compare to sample: fails $r->extractTo(".", NULL, TRUE); assert(SAMPLE_TXT === file_get_contents(SAMPLE_FN)); Expected result: ---------------- Example test.phar.zip UEsDBAAAAAAIAPIOd0a3HaQhEgAAABAAAAANABIAcGhhci10ZXN0LnR4dG51DgBXK0GEtg EAAAAAAAAAAAtOzC3ISVVIzs8rSc0r0eMCAFBLAwQAAAAACADyDndGmVatcj4AAAA8AAAA DgASAC5waGFyL3N0dWIucGhwbnUOAFcrQYS2AQAAAAAAAAAAs7EvyChQ0NdXqMos0E1KLE 5NUSjISCxSSCxKzsgsS1UoLilNUkjLzEnlio/3cPQJiXf29w3w9HEN0tC0BgBQSwMEAAAA AAAAAAgh7IqfoyccAAAAHAAAABMAEgAucGhhci9zaWduYXR1cmUuYmlubnUOAP8S2UEAAA AAAAAAAAAAAgAAABQAAAC/Ml0QwRjS2lNjdmUVA5Z1AsltwFBLAQIAAAAAAAAIAPIOd0a3 HaQhEgAAABAAAAANABIAAAAAAAAAAAAAAAAAAABwaGFyLXRlc3QudHh0bnUOAFcrQYS2AQ AAAAAAAAAAUEsBAgAAAAAAAAgA8g53RplWrXI+AAAAPAAAAA4AEgAAAAAAAAAAAAAATwAA AC5waGFyL3N0dWIucGhwbnUOAFcrQYS2AQAAAAAAAAAAUEsBAgAAAAAAAAAAAAgh7Iqfoy ccAAAAHAAAABMAEgAAAAAAAAAAAAAAywAAAC5waGFyL3NpZ25hdHVyZS5iaW5udQ4A/xLZ QQAAAAAAAAAAAABQSwUGAAAAAAMAAwDuAAAAKgEAAAAA Actual result: -------------- The "Sample content.\n" from test-phar.txt gets created as: 4e0b2dcc49c84855cfce492b2bcde3d1 N�-�IUH��+I�+� -- Edit bug report at https://bugs.php.net/bug.php?id=69279&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69279&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69279&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69279&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=69279&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=69279&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=69279&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=69279&r=needscript Try newer version: https://bugs.php.net/fix.php?id=69279&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=69279&r=support Expected behavior: https://bugs.php.net/fix.php?id=69279&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=69279&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=69279&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=69279&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69279&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=69279&r=dst IIS Stability: https://bugs.php.net/fix.php?id=69279&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=69279&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=69279&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=69279&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=69279&r=mysqlcfg

« previous php.bugs (#191535) next »