php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57905 extracting files from damaged archives hangs in infinite loop and 100% cpu
Submitted: 2007-11-10 02:40 UTC Modified: 2013-02-18 00:35 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: groepaz at gmx dot net Assigned: pajoye (profile)
Status: No Feedback Package: zip (PECL)
PHP Version: 5.2.4 OS: gentoo linux
Private report: No CVE-ID: None
 [2007-11-10 02:40 UTC] groepaz at gmx dot net
Description:
------------
my app is supposed to scan directories for zip files, and put their contents into a database. since i am dealing with thousends of files there, it is likely that every now and then one of these archives is corrupted. it seems that under certain circumstances these archives will open and list their content fine, but extracting data from them fails.

this is what unzip has to say about one of these archives:

$ unzip -t ./test/arch/zip/c64demo.zip
Archive:  ./test/arch/zip/c64demo.zip
error [./test/arch/zip/c64demo.zip]:  missing 1 bytes in zipfile
  (attempting to process anyway)
error [./test/arch/zip/c64demo.zip]:  attempt to seek before beginning of zipfile
  (please check that you have transferred or created the zipfile in the
  appropriate BINARY mode and that you have compiled UnZip properly)
  (attempting to re-compensate)
    testing: 64DEMO.PAS               OK
    testing: MOB64.PAS                bad CRC 893e928b  (should be 3a92f29b)
file #3:  bad zipfile offset (local header sig):  3038
  (attempting to re-compensate)
    testing: NINJA3.PIC               OK
    testing: ZX-FLORD.PIC             OK
    testing: ROZNE.MOB                OK
    testing: SWISS.MBF                OK
    testing: TFIGHT.MOB               OK
    testing: LEONARDO.FNB             OK
    testing: NOTE-1.FNT               OK
    testing: MYLOGOV2.GFX             OK
At least one error was detected in ./test/arch/zip/c64demo.zip.

and zip says:

$ zip -T ./test/arch/zip/c64demo.zip
        zip warning: local header not found for NINJA3.PIC

with this archive, extracting the "MOB64.PAS" file will cause the extension to hang (no matter if i am using getStream/fread or getFromName).

the archive: http://hitmen.c02.at/temp/c64demo.zip

Reproduce code:
---------------
shortened excerpt from my code. i dont think this is relevant, it works fine with thousends of files.

	$za = new ZipArchive();
	$res =$za->open($zipname);
        if ($res === TRUE)		
	{
  	        $finfo=$za->statName($filename);
		$file_size=$finfo['size'];

		if($file_size>$MAX_PACKED_SCAN_FILELENGTH)
		{
			$contents=false;
		}
		else
		{
			 if($file_size>0)
			 {
// it hangs right here				$contents=$za->getFromName($filename);
				 
echo "<br>ZIP contents size:".strlen($contents);flush();ob_flush();	
					if(strlen($contents)!=$file_size)
					{	
						warning(modestr(1)." zip_readfile recorded data does not match unpacked size :".$zipname.":".$filename);
					}
			 }
	    		 else
			 {
			 	$contents=false;
			 	warning(modestr(1)." zip_readfile could not open stream from zero length file ".$zipname.":".$filename);
			 }
		}
		
		$za->close();
		return $contents;
	}
	else
	{
		warning(modestr(1)." zip_readfile could not read from ".$zipname.":".$filename);
		return false;
	}



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-10 02:52 UTC] pierre dot php at gmail dot com
Thanks for the detailed report and sample zip archive, I will try it next week.

In the mean time, can you please try using PHP 5.2.4 or 5.2.5?
 [2007-11-10 03:13 UTC] groepaz at gmx dot net
sorry, my bad. my exact php version is PHP 5.2.4_p20070914-pl2-gentoo ... 

do you think using a different version of php would matter at all? its a bit of a pain to switch forth and back between versions on gentoo :)

btw to add some more, the archive unzips "fine", with only a crc error in one file:

$ unzip c64demo.zip.broken
Archive:  c64demo.zip.broken
error [c64demo.zip.broken]:  missing 1 bytes in zipfile
  (attempting to process anyway)
error [c64demo.zip.broken]:  attempt to seek before beginning of zipfile
  (please check that you have transferred or created the zipfile in the
  appropriate BINARY mode and that you have compiled UnZip properly)
  (attempting to re-compensate)
  inflating: 64DEMO.PAS
  inflating: MOB64.PAS                bad CRC 893e928b  (should be 3a92f29b)
file #3:  bad zipfile offset (local header sig):  3038
  (attempting to re-compensate)
  inflating: NINJA3.PIC
  inflating: ZX-FLORD.PIC
  inflating: ROZNE.MOB
  inflating: SWISS.MBF
  inflating: TFIGHT.MOB
  inflating: LEONARDO.FNB
  inflating: NOTE-1.FNT
  inflating: MYLOGOV2.GFX
 [2007-11-13 11:09 UTC] matt at signpostservices dot co dot uk
I am reproducing the same bug in Windows on the command line execution.
 [2007-12-02 12:12 UTC] pierre dot php at gmail dot com
I can reproduce it as well. I'm working on a fix while updating the library.
 [2008-05-20 19:57 UTC] pierre dot php at gmail dot com
Please try using pecl/zip CVS head.

I plan to release 1.10.0 later this week if all known bugs are fixed :)
 [2008-05-20 20:00 UTC] pierre dot php at gmail dot com
Or using this snap http://blog.thepimp.net/misc/zip-1.10.0.tgz
 [2013-02-18 00:35 UTC] pecl-dev at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC