php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #58169 "Number of files in the Phar" limited to 2042
Submitted: 2008-04-20 12:52 UTC Modified: 2018-01-23 16:33 UTC
From: mike at ziebeck dot net Assigned: bishop (profile)
Status: Closed Package: *General Issues
PHP Version: 5.2.5 OS: Windows XP x64 Pro
Private report: No CVE-ID: None
 [2008-04-20 12:52 UTC] mike at ziebeck dot net
Description:
------------
Adding more than 2042 files results in Fatal error:
 Uncaught exception 'PharException'
 with message       'unable to create temporary file'

According to http://devzone.zend.com/manual/ref.phar.html
 There should be a 4Byte "Number of files in the Phar" limit

Running different test cases, i can see by now:
 * Adding files via transaction does not make a difference
   $p->startBuffering();
   // add files here
   $p->stopBuffering();
 * Mini stub does not make a difference
   $p->setStub('<? __HALT_COMPILER(); ? >');   
   // add files here
 * BZ2 compression does not make a difference
   $p->compress(Phar::BZ2);
   // add files here
 * Using subdirectories containing less than 2000 files
   each does not make a difference too. Stops on the exact
   file.
 * Changing that file (rename, content, removing) does not
   matter. It always stops on file: 2042
 * TEMP and TMP Directory does not matter.
   phpXXXX.tmp files are created/updated/removed frequently
   in there and sufficient disk space is available.  

Script has been run via CLI using parameters:
 php -c php.ini-dist 
     -d extension=php_phar.dll 
     -d phar.readonly=0 
     -f TestPharFileLimit.php

Using v5.2.6RC6-dev Snapshot release:
-------------------------------------
 http://snaps.php.net/win32/php5.2-win32-200804171230.zip
 http://snaps.php.net/win32/pecl5.2-win32-200804171230.zip

Reproduce code:
---------------
<?
$pArchive="DataArchive.phar";
$dirName=str_replace(DIRECTORY_SEPARATOR, "/", dirname(__FILE__));
$p=new Phar("$dirName/$pArchive", 0, $pArchive);
for($i=0; $i<16*1024; $i++){
 echo("\rWriting File($i)          ");
 if(!is_dir($fileDir="$dirName/test_data"))
  mkdir($fileDir, 0777, true);
 file_put_contents("$fileDir/$i", "");
 $p->addFile("$fileDir/$i", "$dirName");
} 	
echo("\r Written Files($i)          \r\n");
?>

Expected result:
----------------
Written Files(16384)

Actual result:
--------------
Writing File(2042)
Fatal error: Uncaught exception 'PharException' with message 'unable to create temporary file' in D:\Php\TestPharFileLim
it.php:10
Stack trace:
#0 D:\Php\TestPharFileLimit.php(10): Phar->addFile('D:/Php/test_dat...', 'D:/Php')
#1 {main}
  thrown in D:\Php\TestPharFileLimit.php on line 10

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-25 12:17 UTC] greg at chiaraquartet dot net
Hi,

I've verified this, but the number varies based on the operating system, for instance, on unix, we're limited to 1018 files before it pukes.  We're simply not closing some temporary file handles, I'll try to figure it out.
 [2008-04-25 12:50 UTC] greg at chiaraquartet dot net
This bug has been fixed in CVS.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pecl.php.net.

In case this was a pecl.php.net website problem, the change will show
up on the website in short time.
 
Thank you for the report, and for helping us make PECL better.

we were missing a php_stream_close() in Phar::addFile(), bug is fixed, thanks for the report.
 [2008-04-28 04:53 UTC] mike at ziebeck dot net
Well done. I've verified this issue again ...

Using win32 snapshot version of PHP 5.2: [Problem fixed]
--------------------------------------------------------
 php5.2-win32-200804280030.zip 
 pecl5.2-win32-200804280030.zip

Using win32 snapshot version of PHP 5.3: [Problem persists]
-----------------------------------------------------------
 php5.3-win32-200804251230.zip
 pecl5.3-win32-200804251230.zip

 * 2042 file limit persists
 * unlinking the temporary file (see new script) results in:
    Warning: Permission denied 

Not tested: win32 snapshot version of PHP 6.0: [no PECL]
--------------------------------------------------------

Reproduce code:
---------------
<?
 $pArchive="DataArchive.phar";
 $dirName=str_replace(DIRECTORY_SEPARATOR, "/", dirname(__FILE__));
 $p=new Phar("$dirName/$pArchive", 0, $pArchive);
 for($i=0; $i<16*1024; $i++){
  echo("\r writing File($i)          ");
  if(!is_dir($fileDir="$dirName/test_data"))
   mkdir($fileDir, 0777, true);
  file_put_contents($tmpFile="$fileDir/$i", "");
  $p->addFile($tmpFile, $i);
  //unlink($tmpFile);
 } 	
 echo("\r Written Files($i)          \r\n");
?>
 [2015-05-28 10:09 UTC] hanskrentel at yahoo dot de
Related:

Bug #53467: Phar cannot compress large archives (Dec 2010)
- https://bugs.php.net/bug.php?id=53467
 [2018-01-23 16:33 UTC] bishop@php.net
-Package: phar +Package: *General Issues -Assigned To: cellog +Assigned To: bishop
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 19:01:28 2024 UTC