|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46985 ZIP can not produce valid archive
Submitted: 2008-12-31 20:27 UTC Modified: 2009-01-02 00:25 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: killerbg at gmail dot com Assigned: pajoye (profile)
Status: Closed Package: Zip Related
PHP Version: 5.2.8 OS: Windows XP Professional SP3
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: killerbg at gmail dot com
New email:
PHP Version: OS:


 [2008-12-31 20:27 UTC] killerbg at gmail dot com
On Windows XP Professional Service Pack 3 with Apache 2.2.11 and PHP 5.2.8 - PHP 5.2.9 loaded as dynamic module when creating archive and adding files and/or folders the ouput is incorrect and the file gets corrupted. Even trying to open it again with the script results error code 19.

Reproduce code:
$file = tempnam("/tmp/", "php");
$zip = new ZipArchive();
if (($zip->open($file, ZipArchive::OVERWRITE)) === TRUE)

Expected result:
Correctly created zip archive file with unique name located in the temporaly directory.

Actual result:
Only the firsts few added files visible but corrupted acording to the crc32 record.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-12-31 21:21 UTC]
I can't reproduce it here (xp sp3 and vista/2k8).

Please provide the file(s) (the minimum required to create a corrupted archive) and the script you are using.
 [2008-12-31 23:12 UTC] killerbg at gmail dot com
Here is an archive containing both the corrupted file created with the new versions, a good file created with the same script and older version (5.2.6) and the script used -
 [2009-01-01 00:38 UTC]
It works just fine here (in apache2 sapi, iis, fcgi and cli).

Can you try the following script please? I suspect some other errors happening and they are not displayed. Be sure to have display_errors activated.

By the way, in the latest releases there are "addFromPattern"/"Glob" functions which let you add recursively something like "*.jpeg" :)

$path = 'C:\yourpath\\';
$count = 0;

function archive($path, $local)
	global $zip, $count;
	if ($handle = opendir($path)) {
		while (($file = readdir($handle)) !== false) {
			if (($file != ".") && ($file != "..")) {
				echo "$file\n";
				var_dump($local, $file, $path);
				if (is_dir($path . $file)) {
					$zip->addEmptyDir($local . $file . "/");
					archive($path . $file . "/", $local . $file . "/");
				} elseif (is_file($path . $file)) {
					if ($count > 128) {
						$count = 0;
					$zip->addFile($path . $file, $local . $file);
	echo "count: $count\n";
$file = '';

$zip = new ZipArchive();

if (($zip->open($file, ZipArchive::CREATE)) === TRUE) {
	archive($path, null);


echo "done\n";

 [2009-01-01 14:44 UTC] php at undoso dot eu
I have the same issue. It seems that compressing short strings works fine but using huge ones gets them corrupted. Even if the resulting zip might open, using a simple md5 on both files often prove that they differs which is not great...

I downloaded PHP 5.2.6 and replaced the php_zip.dll of 5.2.8 by the 5.2.6 version. It fixed the problem right away. There is really some kind of regression in 5.2.8.
 [2009-01-01 16:25 UTC] killerbg at gmail dot com
pajoye(at)php(dot)net, here is the output from your script
(identical with the two versions)
The file working state is the same as with my script
The php(at)undoso(dot)eu's solution is working here too
when combining php5ts.dll version 5.2.9 (CVS)
with php_zip.dll version 5.2.7 (CVS)
 [2009-01-01 20:42 UTC]
Please try using this CVS snapshot:
For Windows:

Please try a 5.2 snapshot, I committed a fix that should fix this issue.
 [2009-01-01 21:29 UTC] killerbg at gmail dot com
Now everything is working fine. Thank you very much!
 [2009-01-02 00:25 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

fixed in 5.2, 5.3, head.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Jan 21 00:03:33 2022 UTC