|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57021 Adding file to zip causes corruption
Submitted: 2006-05-18 04:52 UTC Modified: 2006-08-01 08:54 UTC
From: mpigozzi at e-portaltech dot it Assigned: pajoye (profile)
Status: Closed Package: zip (PECL)
PHP Version: 5.1.2 OS: Linux Fedora Core 4
Private report: No CVE-ID: None
 [2006-05-18 04:52 UTC] mpigozzi at e-portaltech dot it
Using 1.3.1alpha, deleting a file on the root of a zip, then adding a new file with the same name on the same place (root directory), causes a corruption of the whole zip.
This happens only with zips with a directory structure. 

Reproduce code:
$zip = new Zip()

   return false;
for($i=0; $i<$zip->numFiles;$i++) {
     $statzip = $zip->statIndex($i);
     if($statzip['name'] == "foofoo.xml")
//also doing the $zip->addFromString() causes corruption
//$zip->addFromString("", $foofooxml_as_string);

Expected result:
...a zip with the new 'foofoo.xml' on the root of the directory structure

Actual result:
...a corrupted zip (I can see the directory structure with Ark, but then I cannot extract 'foofoo.xml').

As I have tried through Zend debugger, the delete is acting well, but the addFile() causes the corruption.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-18 07:38 UTC] pierre dot php at gmail dot com
Thank you for taking the time to write to us, but this is not
a bug.

You are trying to add the zip itself. The zip being in a undefined state (adding the archive to the archive itself while writing it).
 [2006-05-18 09:29 UTC] mpigozzi at e-portaltech dot it
Sorry, I've made a mistake in the code excerpt I wrote in the example. I mean instead:


When I add a file to an existing archive (with a folder structure) from which I've removed a the same file (in the root), I get a corrupted zip. Just tried again now.

Sorry for the inconvenience.
 [2006-05-18 09:38 UTC] pierre dot php at gmail dot com
I cannot reproduce this problem. Can you provide me the original zip and the foofoo.xml file?
 [2006-05-19 09:24 UTC] pierre dot php at gmail dot com
The problem is due to the bit 3. If this bit is set to 0, the fields crc-32, compressed size and uncompressed size are set to zero in the local header.  The correct values are put in the data descriptor immediately following the compressed         data.

This behavior is not yet supported. A fix is coming.
 [2006-07-08 21:48 UTC] pierre dot php at gmail dot com
Please fetch a CVS verstion and give it a try. I have commited a possible fix, I only tested with one archive (the odt you sent me), You can try with many docs or archives.
 [2006-08-01 08:54 UTC] pierre dot php at gmail dot com
This bug has been fixed in CVS.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on

In case this was a website problem, the change will show
up on the website in short time.
Thank you for the report, and for helping us make PECL better.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Dec 08 09:01:27 2023 UTC