php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74674 Problem of extracting an archive with symbolic links
Submitted: 2017-05-30 14:34 UTC Modified: 2021-09-26 04:22 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: gwenael dot pellen at arkeup dot com Assigned: cmb (profile)
Status: No Feedback Package: PHAR related
PHP Version: 7.1.5 OS: Linux Ubuntu 16.04 LTS
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2017-05-30 14:34 UTC] gwenael dot pellen at arkeup dot com
Description:
------------
$ php -v
PHP 7.1.5-1+deb.sury.org~xenial+2 (cli) (built: May 22 2017 12:48:42) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.1.5-1+deb.sury.org~xenial+2, Copyright (c) 1999-2017, by Zend Technologies

Create my data

$ mkdir /tmp/php-bug/ && cd /tmp/php-bug/
$ mkdir -p source1/dir1
$ mkdir -p source1/dir2
$ mkdir source2
$ ln -s ../source1/dir1 source2/dir1
$ ln -s ../source1/dir2 source2/dir2

Create TAR archive

$ tar cvf source2.tar source2/
source2/
source2/dir1
source2/dir2

Show TAR archive

$ tar tvf source2.tar
drwxr-xr-x root/root         0 2017-05-30 14:00 source2/
lrwxrwxrwx root/root         0 2017-05-30 14:00 source2/dir1 -> ../source1/dir1
lrwxrwxrwx root/root         0 2017-05-30 14:00 source2/dir2 -> ../source1/dir2

Create PHP script to extract this archive.

$ cat > extract.php <<EOT
<?php
    \$path = getcwd();
    echo \$path, "\n";
    \$phar = new PharData('source2.tar');
    \$phar->extractTo(\$path,null,true);
EOT

Launch PHP script

$ php extract.php
/tmp/php-bug
PHP Warning:  PharData::extractTo(/tmp/php-bug/source2/dir1): failed to open stream: Is a directory in /tmp/php-bug/extract.php on line 5
PHP Fatal error:  Uncaught PharException: Extraction from phar "/tmp/php-bug/source2.tar" failed: Cannot extract "source2/dir1", could not open for writing "/tmp/php-bug/source2/dir1" in /tmp/php-bug/extract.php:5
Stack trace:
#0 /tmp/php-bug/extract.php(5): PharData->extractTo('/tmp/php-bug', NULL, true)
#1 {main}
  thrown in /tmp/php-bug/extract.php on line 5

Test script:
---------------
<?php
    $path = getcwd();
    echo $path, "\n";
    $phar = new PharData('source2.tar');
    $phar->extractTo(\$path,null,true);

Expected result:
----------------
$ php extract.php
$

Actual result:
--------------
$ php extract.php
/tmp/php-bug
PHP Warning:  PharData::extractTo(/tmp/php-bug/source2/dir1): failed to open stream: Is a directory in /tmp/php-bug/extract.php on line 5
PHP Fatal error:  Uncaught PharException: Extraction from phar "/tmp/php-bug/source2.tar" failed: Cannot extract "source2/dir1", could not open for writing "/tmp/php-bug/source2/dir1" in /tmp/php-bug/extract.php:5
Stack trace:
#0 /tmp/php-bug/extract.php(5): PharData->extractTo('/tmp/php-bug', NULL, true)
#1 {main}
  thrown in /tmp/php-bug/extract.php on line 5

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-09-16 21:17 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-09-16 21:17 UTC] cmb@php.net
I cannot reproduce this with PHP-7.4 (neither on Debian nor
Windows).  Is this still an issue for you with any of the actively
supported PHP versions[1]?

[1] <https://www.php.net/supported-versions.php>
 [2021-09-26 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun Dec 04 18:05:53 2022 UTC