php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52013 Unable to decompress files in a compressed phar.
Submitted: 2010-06-07 11:55 UTC Modified: 2011-09-01 09:17 UTC
From: frederic dot hardy at mageekbox dot net Assigned: bjori (profile)
Status: Closed Package: PHAR related
PHP Version: 5.3.2 OS: FreeBSD
Private report: No CVE-ID: None
 [2010-06-07 11:55 UTC] frederic dot hardy at mageekbox dot net
Description:
------------
Use Phar::decompressFiles() to decompress files in a phar where files was compressed with Phar::compressFiles(Phar::GZ) throw an exception.

Configure Command =>  './configure'  '--with-layout=GNU' '--with-config-file-scan-dir=/usr/local/etc/php' '--with-mysql=mysqlnd' '--with-mysqli=mysqlnd' '--enable-libxml' '--with-libxml-dir=/usr/local' '--with-pcre-regex=/usr/local' '--program-prefix=' '--disable-cgi' '--with-apxs2=/usr/local/sbin/apxs' '--with-regex=php' '--with-zend-vm=CALL' '--disable-ipv6' '--prefix=/usr/local' '--mandir=/usr/local/man' '--infodir=/usr/local/info/' '--build=i386-portbld-freebsd8.0'

Phar API version : 1.1.1

df -h output : /dev/ad0s1e     66G    7.6G     53G    13%    /usr



Test script:
---------------
<?php

mkdir(__DIR__ . '/files');

for ($file = 1; $file < 50; $file++)
{
	file_put_contents(__DIR__ . '/files/' . $file . '.php', '<?php echo \'' . str_repeat($file, 5000) . '\'; ?>');
}

$phar = new \Phar(__DIR__ . '/compressed.phar');

$phar->buildFromDirectory(__DIR__ . '/files', '/\.php$/');
$phar->setSignatureAlgorithm(\Phar::SHA1);
$phar->compressFiles(\Phar::GZ);

for ($file = 1; $file < 50; $file++)
{
	unlink(__DIR__ . '/files/' . $file . '.php');
}

rmdir(__DIR__ . '/files');

$phar = new \Phar(__DIR__ . '/compressed.phar');

$phar->decompressFiles();

foreach ($phar as $file)
{
	var_dump(file_get_contents($file->getFilename()));
}

?>

Expected result:
----------------
No output and phar was decompressed.

Actual result:
--------------
fch@witchblade:~/tmp/phar
362> php -d phar.readonly=0 generator.php 
PHP Fatal error:  Uncaught exception 'BadMethodCallException' with message 'unable to write contents of file "1.php" to new phar "/usr/home/fch/tmp/phar/compressed.phar"' in /usr/home/fch/tmp/phar/generator.php:25
Stack trace:
#0 /usr/home/fch/tmp/phar/generator.php(25): Phar->decompressFiles()
#1 {main}
  thrown in /usr/home/fch/tmp/phar/generator.php on line 25

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-08 14:33 UTC] felipe@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: cellog
 [2010-07-02 04:45 UTC] ericstewart@php.net
Automatic comment from SVN on behalf of ericstewart
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=300927
Log: Added test for bug 52013 to trunk.
 [2010-07-02 04:46 UTC] ericstewart@php.net
Automatic comment from SVN on behalf of ericstewart
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=300928
Log: Added test for bug 52013 to PHP_5_3.
 [2011-08-29 14:19 UTC] bjori@php.net
Automatic comment from SVN on behalf of bjori
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=315703
Log: Fixed bug#52013 (Unable to decompress files in a compressed phar)
 [2011-08-29 14:20 UTC] bjori@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2011-08-29 14:20 UTC] bjori@php.net
-Status: Assigned +Status: Closed -Assigned To: cellog +Assigned To: bjori
 [2011-09-01 09:17 UTC] mbeccati@php.net
Issue doesn't seem to be fixed on my FreeBSD 6.2 box even using latest 5.4 HEAD.

The phar_stream_copy_to_stream() call returns failure due to an error in the underlying write(). Errno is 14 (Bad address) and my feeling is that the write len ends up being actually bigger than the source buffer.
 [2011-10-13 16:16 UTC] janani at us dot ibm dot com
This issue does not seem to be fixed on my RHEL6 box with php 5.3.3 with the patch for this applied. With the patch, instead of the failure being reported in the  decompressFiles(),there is an error when trying to retrieve the decompressed files in file_get_contents().

Test Results while executing test script provided in the description of this bug:

> php -f test1.php
PHP Warning:  file_get_contents(1.php): failed to open stream: No such file or directory in /tmp/test1.php on line 29
bool(false)
PHP Warning:  file_get_contents(10.php): failed to open stream: No such file or directory in /tmp/test1.php on line 29
bool(false)
PHP Warning:  file_get_contents(11.php): failed to open stream: No such file or directory in /tmp/test1.php on line 29
bool(false)
....
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 09:01:26 2024 UTC