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

Bug #14622 reading tar files with split filenames needs slash inserted
Submitted: 2008-09-08 22:17 UTC
From: sharoncorrell Assigned: doconnor
Status: Assigned Package: File_Archive (version 1.5.4)
PHP Version: 5.2.5 OS: Windows XP
Roadmaps: (Not assigned)    
Subscription  


 [2008-09-08 22:17 UTC] sharoncorrell (Sharon Correll)
Description: ------------ There is code in File_Archive_Writer_Tar::tarHeader to split a long filename (> 100 chars) into two pieces, ie, separating the path out into a separate field. But that field is not written with a slash at the end; nor does the base part of the filename include the intervening slash. So in File_Archive_Reader_Tar::_nextAdvance, it reads the prefix (path) and prepends it on the filename, but since there is no slash, the filename gets messed up. I don't know if (according to the TAR specification) the path SHOULD have the slash included or not. But regardless, if it is not there, it ought to be inserted when reading the file. Here is how I've patched it: if ($header['magic'] == 'ustar') { $prefix = $header['prefix']; if ( strlen( $prefix ) > 0 && $prefix[strlen($prefix) - 1] != "/" ) { $prefix .= "/"; } $this->currentFilename = $this->getStandardURL( $prefix . $header['filename'] ); } else { // etc. }

Comments

 [2008-10-09 13:56 UTC] doconnor (Daniel O'Connor)
Hi Sharon; I don't suppose you can create a small executable test script which demonstrates the problem for those of us less familiar with the package?
 [2008-10-10 16:39 UTC] sharoncorrell (Sharon Correll)
Here is a sample script. Create a small file whose complete filename including the path is longer than 100 characters, similar to $long_filename. Then run the script. The filename read from the tar is incorrect; it does not include the slash after the last directory name. <?php $long_filename = "C:/tmp/directory/to_test/PEAR/FileArchive/Bug/file_with_a_long_name_abcdefghijklmnopqrstuvwxyz_0123456789.txt"; $path = ( "." . PATH_SEPARATOR . "inc" . PATH_SEPARATOR . "inc/PEAR" ); ini_set( "include_path", $path ); require_once 'inc/PEAR/File/Archive.php'; set_magic_quotes_runtime(0); // Export the tar file. $reader = File_Archive::read( $long_filename, $long_filename ); $tar_filename = "C:/package.tar"; $writer = File_Archive::toVariable( $tar_output ); $archive = File_Archive::toArchive( $long_filename, $writer ); File_Archive::extract( $reader, $archive ); // do the export, which puts data into $tar_output $file_pointer = @fopen( $tar_filename, "wb" ); fwrite( $file_pointer, $tar_output, strlen( $tar_output ) ); @fclose( $file_pointer ); // Now read it again. $tar_reader = File_Archive::read( $tar_filename . "/" ); // read all the files while ( $tar_reader->next() ) { $filename_in_tar = $tar_reader->getFilename(); // This prints the wrong filename: echo( "Found file " . $filename_in_tar . "\n" ); } ?>
 [2010-09-06 19:03 UTC] doconnor (Daniel O'Connor)
-Assigned To: +Assigned To: doconnor
 [2010-09-06 19:05 UTC] doconnor (Daniel O'Connor)