FAQ
Edit report at http://pear.php.net/bugs/bug.php?id=13322&edit=1

ID: 13322
Updated by: mrook@php.net
Reported By: pascal dot vogels at philips dot com
Summary: Extracting of archive containing symlinks fails
Status: Assigned
Type: Bug
Package: Archive_Tar
Operating System: Windows
Package Version: 1.3.2
PHP Version: 5.2.0
Assigned To: mrook
-Roadmap Versions: 1.3.4, 1.3.6
+Roadmap Versions: 1.3.6
New Comment:

-Roadmap Versions: 1.3.4, 1.3.6
+Roadmap Versions: 1.3.6



Previous Comments:
------------------------------------------------------------------------

[2009-08-11 20:34:08] mrook

-Summary: Extracting of archive containing zero-size
file fails
+Summary: Extracting of archive containing symlinks
fails
-Assigned To:
+Assigned To: mrook


------------------------------------------------------------------------

[2009-01-22 09:43:19] nath

I have come across this problem too.
I'm running IIS7 on Windows Vista with PHP 5.2.5

Although Vista does support symlinks (a.k.a Junctioning) it's
not an easy thing to try and get working and I'm guessing
would result in some problems when trying to TAR things up
again. Instead I've written a little workaround (well more of a
hack actually) to have symlinks on Windows extract. I believe
this is how WinRAR handles the situation.

This code simply looks for the linked file in the archive and
extracts that instead under the name of the link. If the symlink
was originally to something outside of the TAR then it'd be
broken anyway if you're extracting onto Windows and so in
this case it writes a little comment in a file under the name of
the link. This does mean that the two files (original and
symlinked one) are now separate entities and as such it should
be noted that modifying one will not modify the other.

Simply replace line 1533 of Tar.php with the following:
(Because of line wrapping in this comment post, I will number
each new line. You will have to manually remove the false line
breaks.)

1533: if (defined('OS_WINDOWS') && OS_WINDOWS) {
1534: if (($v_dest_file = @fopen($v_header['filename'],
"wb")) == 0) {
1535: $this->_error('Error while opening
{'.$v_header['filename'].'} in write binary mode');
1536: return false;
1537: } else {
1538: $temp = new Archive_Tar($this->_tarname, $this-
_compress_type);
1539: $v_link_file =
substr(substr($v_header['filename'],0,strrpos($v_header['filena
me'],"/")+1),strlen($p_path)+1).$v_header['link'];
1540: $v_content = $temp->extractInString($v_link_file);
1541: unset($temp);
1542: if(!is_null($v_content)) {
1543: fwrite($v_dest_file, $v_content);
1544: } else {
1545: // Symbolic Link is broken or links to something
outside of tar file. For Windows we'll create it as a text file
with a note in it.
1546: fwrite($v_dest_file, "This file represents a UNIX
symbolic link to ".$v_header['link']."\r\nThe linked file was not
found in the archive.");
1547: }
1548: }
1549: @fclose($v_dest_file);
1550: } else if (!@symlink($v_header['link'],
$v_header['filename'])) {

If you think this is worthwhile hopefully the authors may add it
to an official release.

Nath.

P.S. As an improvement it might be worthwhile doing a check
for the existence of the original file and copying it to a file
with the link name before we go hunting through the archive
again. In case we already extracted the linked file.

------------------------------------------------------------------------

[2008-03-06 04:05:43] pascal

Closer investigation shows that the zero-size file is a symbolic link.
Calling the symlink function in Windows causes a fatal error:

"Fatal error: Call to undefined function symlink()"

So, this piece of code in the Tar.php file doesn't seem to work
properly:

...
} elseif ($v_header['typeflag'] == "2") {
if (!@symlink($v_header['link'], $v_header['filename']))
{
$this->_error('Unable to extract symbolic link {'
.$v_header['filename'].'}');
return false;
}
...

Furthermore, in Linux (using PHP 5.1.4) the symlink command itself
seems to work (duh...), but the Archive_Tar class doesn't seem to create
a symbolic link, but an ordinary file instead.

------------------------------------------------------------------------

[2008-03-06 02:43:19] pascal

Description:
------------
Extracting a .tar.gz archive containing zero-size file fails.
Extraction stops when a zero-size file is encountered (so the extraction
only partially succeeds).

------------------------------------------------------------------------

Search Discussions

  • Mrook at Mar 9, 2010 at 9:29 am
    Edit report at http://pear.php.net/bugs/bug.php?id=13322&edit=1

    ID: 13322
    Updated by: mrook@php.net
    Reported By: pascal dot vogels at philips dot com
    Summary: Extracting of archive containing symlinks fails
    Status: Assigned
    Type: Bug
    Package: Archive_Tar
    Operating System: Windows
    Package Version: 1.3.2
    PHP Version: 5.2.0
    Assigned To: mrook
    -Roadmap Versions: 1.3.6
    +Roadmap Versions: 1.3.7
    New Comment:

    -Roadmap Versions: 1.3.6
    +Roadmap Versions: 1.3.7



    Previous Comments:
    ------------------------------------------------------------------------

    [2010-03-09 09:27:37] mrook

    -Roadmap Versions: 1.3.4, 1.3.6
    +Roadmap Versions: 1.3.6


    ------------------------------------------------------------------------

    [2009-08-11 20:34:08] mrook

    -Summary: Extracting of archive containing zero-size
    file fails
    +Summary: Extracting of archive containing symlinks
    fails
    -Assigned To:
    +Assigned To: mrook


    ------------------------------------------------------------------------

    [2009-01-22 09:43:19] nath

    I have come across this problem too.
    I'm running IIS7 on Windows Vista with PHP 5.2.5

    Although Vista does support symlinks (a.k.a Junctioning) it's
    not an easy thing to try and get working and I'm guessing
    would result in some problems when trying to TAR things up
    again. Instead I've written a little workaround (well more of a
    hack actually) to have symlinks on Windows extract. I believe
    this is how WinRAR handles the situation.

    This code simply looks for the linked file in the archive and
    extracts that instead under the name of the link. If the symlink
    was originally to something outside of the TAR then it'd be
    broken anyway if you're extracting onto Windows and so in
    this case it writes a little comment in a file under the name of
    the link. This does mean that the two files (original and
    symlinked one) are now separate entities and as such it should
    be noted that modifying one will not modify the other.

    Simply replace line 1533 of Tar.php with the following:
    (Because of line wrapping in this comment post, I will number
    each new line. You will have to manually remove the false line
    breaks.)

    1533: if (defined('OS_WINDOWS') && OS_WINDOWS) {
    1534: if (($v_dest_file = @fopen($v_header['filename'],
    "wb")) == 0) {
    1535: $this->_error('Error while opening
    {'.$v_header['filename'].'} in write binary mode');
    1536: return false;
    1537: } else {
    1538: $temp = new Archive_Tar($this->_tarname, $this-
    _compress_type);
    1539: $v_link_file =
    substr(substr($v_header['filename'],0,strrpos($v_header['filena
    me'],"/")+1),strlen($p_path)+1).$v_header['link'];
    1540: $v_content = $temp->extractInString($v_link_file);
    1541: unset($temp);
    1542: if(!is_null($v_content)) {
    1543: fwrite($v_dest_file, $v_content);
    1544: } else {
    1545: // Symbolic Link is broken or links to something
    outside of tar file. For Windows we'll create it as a text file
    with a note in it.
    1546: fwrite($v_dest_file, "This file represents a UNIX
    symbolic link to ".$v_header['link']."\r\nThe linked file was not
    found in the archive.");
    1547: }
    1548: }
    1549: @fclose($v_dest_file);
    1550: } else if (!@symlink($v_header['link'],
    $v_header['filename'])) {

    If you think this is worthwhile hopefully the authors may add it
    to an official release.

    Nath.

    P.S. As an improvement it might be worthwhile doing a check
    for the existence of the original file and copying it to a file
    with the link name before we go hunting through the archive
    again. In case we already extracted the linked file.

    ------------------------------------------------------------------------

    [2008-03-06 04:05:43] pascal

    Closer investigation shows that the zero-size file is a symbolic link.
    Calling the symlink function in Windows causes a fatal error:

    "Fatal error: Call to undefined function symlink()"

    So, this piece of code in the Tar.php file doesn't seem to work
    properly:

    ...
    } elseif ($v_header['typeflag'] == "2") {
    if (!@symlink($v_header['link'], $v_header['filename']))
    {
    $this->_error('Unable to extract symbolic link {'
    .$v_header['filename'].'}');
    return false;
    }
    ...

    Furthermore, in Linux (using PHP 5.1.4) the symlink command itself
    seems to work (duh...), but the Archive_Tar class doesn't seem to create
    a symbolic link, but an ordinary file instead.

    ------------------------------------------------------------------------

    [2008-03-06 02:43:19] pascal

    Description:
    ------------
    Extracting a .tar.gz archive containing zero-size file fails.
    Extraction stops when a zero-size file is encountered (so the extraction
    only partially succeeds).

    ------------------------------------------------------------------------

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedMar 9, '10 at 8:32a
activeMar 9, '10 at 9:29a
posts2
users1
websitepear.php.net

1 user in discussion

Mrook: 2 posts

People

Translate

site design / logo © 2022 Grokbase