#44974 [Fbk->Opn]: ZipArchive can't open large archives

From: Date: Fri, 08 Aug 2008 00:31:49 +0000
Subject: #44974 [Fbk->Opn]: ZipArchive can't open large archives
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-127752@lists.php.net to get a copy of this message
 ID:               44974
 User updated by:  florian dot ember at gmail dot com
 Reported By:      florian dot ember at gmail dot com
-Status:           Feedback
+Status:           Open
 Bug Type:         Zip Related
 Operating System: Debian
 PHP Version:      5.2.6
 Assigned To:      pajoye
 New Comment:

Sorry, I can't do that. I ran the reproduce code on a shared host and I
don't have a Debian / Linux installation at hand.


Previous Comments:
------------------------------------------------------------------------

[2008-08-07 23:43:08] pajoye@php.net

Please try using this CVS snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows (zip):
 
  http://snaps.php.net/win32/php5.3-win32-latest.zip

For Windows (installer):

  http://snaps.php.net/win32/php5.3-win32-installer-latest.msi



------------------------------------------------------------------------

[2008-07-29 11:07:39] vadim at vadiaz dot com

This looks like exactly the same bug as
http://bugs.php.net/bug.php?id=44055 - zip
archive with more than 1000
entries in root or archive produce an error on 64bit Linux systems
I fixed it and rebuild php from source for my servers
the patch is:

--- php-5.2.6.orig/ext/zip/lib/zip_open.c	2008-01-14 05:19:41.000000000
+0200
+++ php-5.2.6/ext/zip/lib/zip_open.c	2008-07-29 14:04:36.000000000
+0300
@@ -313,7 +313,7 @@
 	/* go to start of cdir and read it entry by entry */
 	bufp = NULL;
 	clearerr(fp);
-	fseek(fp, -(cd->size+cd->comment_len+EOCDLEN), SEEK_END);
+	fseek(fp, -((long)(cd->size+cd->comment_len+EOCDLEN)), SEEK_END);
 	if (ferror(fp) || ((unsigned int)ftell(fp) != cd->offset)) {
 	    /* seek error or offset of cdir wrong */
 	    if (ferror(fp))

------------------------------------------------------------------------

[2008-05-12 18:19:40] florian dot ember at gmail dot com

Description:
------------
Opening archives with more than 1300 or so files fails with ER_READ. I
encountered this while using the close/reopen method to avoid using up
all available filehandles. On a Windows box the script below runs
without errors.

Reproduce code:
---------------
<?php
$za = new ZipArchive;
$za->open('./useless.zip', ZipArchive::CREATE);
for ($i = 1; $i <= 2000; ++$i) {
	$file = "$i.txt";
	touch($file);
	if (!$za->addFile("./$file", $file)) {
		exit("Couldn't add $file");
	}
	echo "Added $file<br />\n";
	if ($za->numFiles % 100 == 0) {
		$za->close();
		$res = $za->open('./useless.zip', ZipArchive::CREATE);
		if ($res !== true) {
			exit("Close/reopen: Error #$res @ $i");
		}
		echo "Close/reopen @ $i<br />\n";
	}
}
unlink('./useless.zip');
echo 'Done.';

Expected result:
----------------
Added 1.txt
Added 2.txt
[...]
Added 2000.txt
Done.

Actual result:
--------------
Added 1.txt
Added 2.txt
[...]
Added 1299.txt
Close/reopen: Error #5 @ 1300


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=44974&edit=1



Thread (8 messages)

« previous php.bugs (#127752) next »