|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47023 ZipArchive fails under certain circumstances
Submitted: 2009-01-07 09:24 UTC Modified: 2009-01-12 09:42 UTC
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: cristi at imagis dot ro Assigned:
Status: Closed Package: Zip Related
PHP Version: 5.2.8 OS: Windows XP SP3
Private report: No CVE-ID: None
 [2009-01-07 09:24 UTC] cristi at imagis dot ro
I am experiencing some problems with ZipArchive, using PHP 5.2.8, with php_zip supplied with this distribution. I am trying to archive couple of folders and files using ZipArchive.

If i am replacing php_zip.dll with php_zip.dll from PHP 5.2.6 it works without problems.

Testing same code using a PHP 5.2.7 installation (with php_zip.dll of 5.2.7) crashes archive also (see Expected Results section).

Reproduce code:
class My_ZipArchive extends ZipArchive
	public function addDir($filename, $localname)
 		// Adds a directory recursivelly, keeping the same structure.
		// @param string $filename The path to the file to add.
		// @param string $localname Local name inside ZIP archive.
		if($localname == NULL || empty($localname))
			$localpath = "";
			$localpath = $localname . '/';
		$iter = new DirectoryIterator($filename);
		foreach($iter as $file)
			// Only zip real files: no dots, no links.
			if ($file->isDot() || (!$file->isFile() && !$file->isDir())) {
			$method = $file->isFile() ? 'addFile' : 'addDir';
			echo $file->getPathname().' - '.$method.'<br />';
			$this->$method($file->getPathname(),  $localpath.$file->getFilename());

				//create output archive
				$zip = new My_ZipArchive();
				$zip->open( '', ZIPARCHIVE::CREATE);
				$zip->addDir( 'd:\_Work\test\output', '');
				$result = $zip->close();
				//finish create output archive
			catch(Exception $e) {
    			echo 'Caught exception: ',  $e->getMessage(), "\n";

Expected result:
This code should make a zip with my files.

Actual result:
If i have 3 .php files to add them to zip i got a corrupted archive. 

If i remove one of them i got a good zip archive.

If i am opening corrupted archive with a zip utility archive doesn't seems to have any files within or is reported directly as corrupted. If i am using a repair tool i got a working archive.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-01-07 09:36 UTC]
Seems to be the same problem than #46985, which is fixed now.

Please try a snapshot (
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Feb 26 19:01:29 2024 UTC