Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.4.14

Bug #13322 Extracting of archive containing symlinks fails
Submitted: 2008-03-06 07:43 UTC
From: pascal Assigned: mrook
Status: No Feedback Package: Archive_Tar (version 1.3.2)
PHP Version: 5.2.0 OS: Windows
Roadmaps: (Not assigned)    
Subscription  


 [2008-03-06 07:43 UTC] pascal (Pascal Vogels)
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).

Comments

 [2008-03-06 09:05 UTC] pascal (Pascal Vogels)
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.
 [2009-01-22 14:43 UTC] nath (Nath Papadacis)
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.
 [2009-08-12 00:34 UTC] mrook (Michiel Rook)
-Summary: Extracting of archive containing zero-size file fails +Summary: Extracting of archive containing symlinks fails -Assigned To: +Assigned To: mrook
 [2010-03-09 14:27 UTC] mrook (Michiel Rook)
-Roadmap Versions: 1.3.4, 1.3.6 +Roadmap Versions: 1.3.6
 [2010-03-09 15:25 UTC] mrook (Michiel Rook)
-Roadmap Versions: 1.3.6 +Roadmap Versions: 1.3.7
 [2010-04-26 02:30 UTC] mrook (Michiel Rook)
-Roadmap Versions: 1.3.7 +Roadmap Versions: 1.3.8
 [2012-01-25 19:53 UTC] doconnor (Daniel O'Connor)
-Status: Assigned +Status: Feedback
Can you do this as a proper patch against svn by any chance?
 [2012-02-17 00:36 UTC] mrook (Michiel Rook)
Thank you for this bug report. To properly diagnose the problem, we need a backtrace to see what is happening behind the scenes. To find out how to generate a backtrace, please read http://bugs.php.net/bugs-generating-backtrace.php Once you have generated a backtrace, please submit it to this bug report and change the status back to "Open". Thank you for helping us make PEAR better. Not sure this bug is still applicable. According to http://www.w3schools.com/browsers/browsers_os.asp Windows 7 is the dominant OS and that OS supports symlinks.
 [2012-11-17 20:53 UTC] mrook (Michiel Rook)
-Status: Feedback +Status: No Feedback
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 "Open". Thank you.