php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67761 Phar::mapPhar fails for Phars inside a path containing ".tar"
Submitted: 2014-08-04 17:58 UTC Modified: -
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: kostik dot lv at gmail dot com Assigned:
Status: Closed Package: PHAR related
PHP Version: 5.4.31 OS: Windows, Linux
Private report: No CVE-ID: None
 [2014-08-04 17:58 UTC] kostik dot lv at gmail dot com
Description:
------------
If you trying to run a phar file from a directory which path contains ".tar" inside, it fails. 

To reproduce, create a simple phar with the attached test script, and then:
mkdir blah.tar-blah
cp test.phar ./blah.tar-blah/

And try running:
php ./blah.tar-blah/test.phar

The bug is most probably caused by this line: http://lxr.php.net/xref/PHP_5_4/ext/phar/tar.c#116

It's funny that I came across this when one of my colleagues was unable to run 'composer.phar' on our new server. The home directories are using lower-cased "first.last" naming pattern there and the colleague happened to have a last name  starting with Tar :) It took a while to figure out that you can't run Phars if you last name starts with Tar :)

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

$phar = new Phar('test.phar');
$phar->addFromString('test.php', '<?php echo "Test";');
$longFile = str_repeat("# just some dummy stuff\n", 500);
$phar->addFromString('some.txt', $longFile);

$stub = <<<'EOF'
#!/usr/bin/env php
<?php

Phar::mapPhar('test.phar');

require 'phar://test.phar/test.php';

__HALT_COMPILER();
EOF;

$phar->setStub($stub);

Expected result:
----------------
"Test" being output

Actual result:
--------------
PHP Fatal error:  Uncaught exception 'PharException' with message 'phar error: "/root/blah.tar-blah/test.phar" is a corrupted tar file (checksum mismatch of file "#!/usr/bin/env php
<?php

Phar::mapPhar('test.phar');

require 'phar://test.phar/test.php';

__HALT_")' in /root/blah.tar-blah/test.phar:4
Stack trace:
#0 /root/blah.tar-blah/test.phar(4): Phar::mapPhar('test.phar')
#1 {main}
  thrown in /root/blah.tar-blah/test.phar on line 4


Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-03-30 12:46 UTC] mike@php.net
Automatic comment on behalf of mike
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8f7e378b9f2fb4f2bb5605d9440d7d34bee6978a
Log: fix bug #67761
 [2015-03-30 12:46 UTC] mike@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 03:01:29 2024 UTC