|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-04-22 14:38 UTC] php at codecaster dot nl
Description:
------------
When you use ZipArchive->addFile() on an empty file, the file will be compressed anyway. This is incorrectly read by some (older) decompression programs.
Reproduce code:
---------------
if (file_put_contents("empty.txt", "") === false) {
die("Cannot write files");
}
$zip = new ZipArchive();
$zip->open("corrupt.zip", ZIPARCHIVE::CREATE);
$zip->addFile("empty.txt");
$zip->close();
Expected result:
----------------
A zip file containing empty.txt with a size of 0 bytes and a compressed size of 0 bytes.
Actual result:
--------------
A zip file containing empty.txt with a size of 0 bytes and a compressed size of 2 bytes.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 03 10:00:01 2025 UTC |
I have installed the latest build, PHP 5.2.10-dev. Same results. From phpinfo(): Zip enabled Extension Version $Id: php_zip.c,v 1.1.2.50 2009/03/01 17:35:25 iliaa Exp $ Zip version 1.8.11 Libzip version 0.9.0 Updated test script (will output 2, should be 0): <?php // create empty file if (file_put_contents("empty.txt", "") === false) { die("Cannot write files"); } // zip it using ZipArchive $zip = new ZipArchive(); $zip->open("corrupt.zip", ZIPARCHIVE::CREATE); $zip->addFile("empty.txt"); $zip->close(); // open the file, show compressed size (returns 2, should be 0) if (($zip = zip_open("corrupt.zip"))) { // read first entry $zip_entry = zip_read($zip); echo "Compressed Size: " . zip_entry_compressedsize($zip_entry); zip_close($zip); } ?>