php.net |  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
Votes:1
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: cristi at imagis dot ro
New email:
PHP Version: OS:

 

 [2009-01-07 09:24 UTC] cristi at imagis dot ro
Description:
------------
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 = "";
		else
		{
			$localpath = $localname . '/';
			$this->addEmptyDir($localname);
		}
		
		$iter = new DirectoryIterator($filename);
		
		foreach($iter as $file)
		{
			// Only zip real files: no dots, no links.
			if ($file->isDot() || (!$file->isFile() && !$file->isDir())) {
				continue;
			}
	
			$method = $file->isFile() ? 'addFile' : 'addDir';
	
			echo $file->getPathname().' - '.$method.'<br />';
			
			$this->$method($file->getPathname(),  $localpath.$file->getFilename());
		}
	}
}

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

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.

Patches

Pull Requests

History

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

Please try a snapshot (http://windows.php.net/snapshots/)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 11:01:29 2024 UTC