php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57245 max number of files = 509?
Submitted: 2006-09-15 13:29 UTC Modified: 2006-09-15 17:45 UTC
From: bartlewis at gmail dot com Assigned: pajoye
Status: Not a bug Package: zip (PECL)
PHP Version: 5.1.2 OS: WinXP Pro and Server 2003
Private report: No CVE-ID:
 [2006-09-15 13:29 UTC] bartlewis at gmail dot com
Description:
------------
In my test cases this extensions sometimes failed and other times worked. After a bit of debugging it seems that 509 files is the tipping point. If you try to pack up file 510 it will fail every time.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-15 13:30 UTC] pierre dot php at gmail dot com
Can you paste here a link to this archive please?
 [2006-09-15 13:47 UTC] pierre dot php at gmail dot com
I tried to modify or create an archive and add 10000 files, it works out of the box on windows, linux and bsd.

Please provide a small script to reproduce your problem. Also what do you mean by "it will fail", any error message? what is the status($zip->status)?
 [2006-09-15 14:07 UTC] bartlewis at gmail dot com
My status on failure is 11.

Here is a link to my test case. It allows you to specify how many files (max) to zip up. I consistently get a $zip->status of 11 as soon as I attempt to zip up more than 509 files. Included in this zip is a large number of files for you to test with, although I get the same effect when I use different files too.

http://www.drcwbt.com/gehres/ZipArchiveTestCase.zip
 [2006-09-15 14:37 UTC] pierre dot php at gmail dot com
Please copy here the informations about the Zip extension in phpinfo();

I suppose you are using a dll from pecl4win?
 [2006-09-15 14:41 UTC] pierre dot php at gmail dot com
Also try:
<?php
        
$zip = new ZipArchive();
$filename = '8714.zip';
if($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE)
{
	exit("failed to open the archive\n");
}
for ($i = 0; $i <10000; $i++) {
	$zip->addFromString('testfile' . sprintf('%03d', $i) . '.txt', 'This is a test string added.');
}
$zip->close();
var_dump(sprintf('%03d', 0));

It works well here using the version available in 5.2, please try this script with your PHP and the latest snapshot for php 5.2
 [2006-09-15 14:45 UTC] bartlewis at gmail dot com
Zip: enabled
Extension Version: $Id: php_zip.c,v 1.73 2006/08/26 12:17:31 pajoye Exp $
Zip version: @PACKAGE_VERSION@
Libzip version: 0.7.1

Downloaded from: http://pecl4win.php.net/ext.php/php_zip.dll
 [2006-09-15 14:51 UTC] pierre dot php at gmail dot com
Thanks a lot for your answers!

The dll seems outdated.

Can you try using php 5.2 snapshot (zip is bundled):

http://snaps.php.net
 [2006-09-15 15:05 UTC] bartlewis at gmail dot com
I can't upgrade to php 5.2 immediately. I'll write back with results when I do.

Your sample code worked fine on my php 5.1.2 and successfully created thousands of files in the zip.

I modified your code slightly (included below) and again it dies when trying to add more than 508 files.

When this script fails the $status is 12.

<?php     
$zip = new ZipArchive();
$filename = '8714f.zip';
if($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE)
{
	exit("failed to open the archive\n");
}
for ($i = 0; $i <510; $i++) {
	$zip->addFile('blank.htm', 'testfile'.$i.'.txt');
}
$zip->close();
echo $zip->status;
?>
 [2006-09-15 15:12 UTC] pierre dot php at gmail dot com
ok, I'm 99.99% sure about the source of the bug.

If you use an absolute path, it will work. This bug was due to some non crossplatform bahaviors on windows. Try:

$zip->addFile(realpath('blank.htm'), 'testfile'.$i.'.txt');

This bug is fixed in CVS and in php 5.2. pecl4win should provide the latest version as well, I will verify later why it does not.

By the way, you don't need to update your install to use the snapshot, just uncompress it somewhere and call php from the cmd line.
 [2006-09-15 15:34 UTC] bartlewis at gmail dot com
Cool, never ran a snapshot from the comman line. Just popped my cherry. :) Thanks for the tip.

OK, I tried your suggestion in the 5.2 snapshot and my php5.1.2. Both produced the same results.

I tried both of these lines in my loop:
$zip->addFile('D:\localhost\Inetpub\xp22\blank.htm', 'testfile'.$i.'.txt');
$zip->addFile(realpath('blank.htm'), 'testfile'.$i.'.txt');

If the loop runs 1-508 times the file is written correctly. 509+ loops and the zip fails with a status of 12.
 [2006-09-15 16:03 UTC] pierre dot php at gmail dot com
OK, another explanation, you reached the file handles limit.

1 handle the php script
1 handle the zip archive
1 handle the extension
509 handles (509 tmp files for the entries)
512 handles

I think it is the limit of windows XP Home. I use XP Pro 64bit and Server 2003 without troubles (same for XP Pro X86).

What I suggest is to close the archive at 500~ and reopen it. It will close the handles while closing the archive.

I thank you for the detailed info. However I cannot provide a fix, this is a Win XP Home "limitation". Future versions of php may have a work around, but now warranty.
 [2006-09-15 16:28 UTC] bartlewis at gmail dot com
OK, thanks a ton! I just tested that workaround of closing the zip and re-opening it after 500 files and it works like a charm.

Just so you know, I'm experiencing this bug on the following platforms (neither are XP Home):

1) XP Media Center SP2 (basically XP-Pro)
2) Windows Server 2003 Web Edition
 [2006-09-15 17:45 UTC] pierre dot php at gmail dot com
ok.

For the record here, after a deeper investigation:

This is not an OS limit, but is a Microsoft's hard coded limit into the MS C Runtime libraries (msvcrt.dll). You can increase this limit rebuilding from sources the runtime libraries (are the sources public in VC?).

The bad news is that it depends on a dll version and not on which Windows you use, making a reliable detection more tricky.
 [2009-09-10 11:45 UTC] dressler at geva dot com
Hello!

Somebody fix this problem?

I have the same problem and cannot find an update for that.

Thank!
 [2009-10-08 08:18 UTC] sam at dogmaconsult dot de
I do not think that the status "Bogus" is correct on this one. All other zip tools (the linux zip command line tool, for example) can handle zip archives with an unlimited amount of files in it. I cannot see a reason why the ZIPArchive class should be unable to do this.

Additionally, I do not see a reason why the function should need a file handler for EVERY file it will unzip - it is unzipping one file at a time, isn't it?

This is a serious bug that makes the use of ZIPArchive impossible under many use cases!
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sun Apr 20 08:02:33 2014 UTC