php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54289 Phar::extractTo() does not accept specific directories to be extracted
Submitted: 2011-03-17 10:44 UTC Modified: 2018-01-06 07:26 UTC
Votes:14
Avg. Score:3.9 ± 1.2
Reproduced:13 of 13 (100.0%)
Same Version:2 (15.4%)
Same OS:1 (7.7%)
From: hpdl at oscommerce dot com Assigned: bishop (profile)
Status: Closed Package: PHAR related
PHP Version: 5.3.5 OS: MacOS 10.6.6
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: hpdl at oscommerce dot com
New email:
PHP Version: OS:

 

 [2011-03-17 10:44 UTC] hpdl at oscommerce dot com
Description:
------------
Phar::extractTo() does not allow specific directories to be extracted. The 
documentation states the second parameter can be a file or directory to only 
extract the file or directory from the phar archive.

Specific files can be extracted however an exception is thrown when a directory is 
passed.

Test script:
---------------
<?php
  $phar = new Phar('/tmp/test.phar');
  $phar->buildFromDirectory('/path/to/source');
  unset($phar);

  $phar = new Phar('/tmp/test.phar');
  $phar->extractTo('/tmp/test/', 'subdir1/subdir2/', true); // throws exception
//  $phar->extractTo('/tmp/test/', 'subdir1/subdir2/file.txt', true); // works as intended
?>


Expected result:
----------------
The specific directory should be extracted from the phar archive.

Actual result:
--------------
Fatal error: Uncaught exception 'PharException' with message 'Phar Error: 
attempted to extract non-existent file "subdir1/subdir2/" from phar 
"/tmp/test.phar"' in /phar-test.php on line 7

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-08-11 20:33 UTC] hpdl at oscommerce dot com
Bug still exists in PHP 5.3.7RC5.
 [2011-08-27 06:28 UTC] cweiske@php.net
I can confirm that - extracting directories does not work:

PHP Fatal error:  Uncaught exception 'PharException' with message
'Phar Error: attempted to extract non-existent file "doc/" from phar
"/home/cweiske/Dev/semanticscuttle/cwdev/dist/SemanticScuttle-0.98.X.phar"'
in /home/cweiske/Dev/semanticscuttle/cwdev/phartest.php:3

Stack trace:
#0 /home/cweiske/Dev/semanticscuttle/cwdev/phartest.php(3): Phar->extractTo('/tmp/test/', 'doc/', true)
#1 {main}
  thrown in /home/cweiske/Dev/semanticscuttle/cwdev/phartest.php on line 3
 [2015-01-02 14:49 UTC] kassner@php.net
Reproducible on PHP 5.6.4.
 [2015-03-30 18:49 UTC] mike@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: mike
 [2017-10-24 05:18 UTC] kalle@php.net
-Status: Verified +Status: Assigned
 [2017-10-24 06:40 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: mike +Assigned To:
 [2018-01-06 05:25 UTC] bishop@php.net
-Status: Open +Status: Analyzed -Assigned To: +Assigned To: bishop
 [2018-01-06 05:25 UTC] bishop@php.net
Occurs because the extractTo implementation scans the manifest -- which only contains file leaves. A pattern based scan is called for here.
 [2018-01-06 06:52 UTC] bishop@php.net
Proposed fix at PR 3008

https://github.com/php/php-src/pull/3008
 [2018-01-06 07:26 UTC] bishop@php.net
Correction: that should be PR #3009

https://github.com/php/php-src/pull/3009
 [2018-01-28 20:55 UTC] nikic@php.net
Automatic comment on behalf of bishop.bettini@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=fa586cee3ec4aa646b524737e1199fe9789c067d
Log: Fixed bug #54289
 [2018-01-28 20:55 UTC] nikic@php.net
-Status: Analyzed +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 16:01:33 2024 UTC