php.net |  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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mpigozzi at e-portaltech dot it
New email:
PHP Version: OS:

 

 [2006-05-18 04:52 UTC] mpigozzi at e-portaltech dot it
Description:
------------
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()

if(!$zip->open("foo.zip"))
   return false;
//delete
for($i=0; $i<$zip->numFiles;$i++) {
     $statzip = $zip->statIndex($i);
     if($statzip['name'] == "foofoo.xml")
         $zip->delete($i);
}
//add
$zip->addFile("foo.zip","foofoo.xml");
//also doing the $zip->addFromString() causes corruption
//$zip->addFromString("foo.zip", $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.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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:

...
$zip->addFile("./temp/foofoo.xml","/foofoo.xml");
...

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 pecl.php.net.

In case this was a pecl.php.net 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-2021 The PHP Group
All rights reserved.
Last updated: Thu Dec 02 21:03:34 2021 UTC