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

ID: 14622
Updated by: daniel.oconnor@gmail.com
Reported By: sharon_correll at sil dot org
Summary: reading tar files with split filenames needs slash
inserted
Status: Open
Type: Bug
Package: File_Archive
Operating System: Windows XP
Package Version: 1.5.4
PHP Version: 5.2.5
-Assigned To:
+Assigned To: doconnor
Roadmap Versions:
New Comment:

-Assigned To:
+Assigned To: doconnor



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

[2008-10-10 12:39:10] sharoncorrell

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" );
}

?>

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

[2008-10-09 09:56:59] doconnor

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-09-08 18:17:11] sharoncorrell

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.
}

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

Search Discussions

  • Daniel Oconnor at Sep 6, 2010 at 3:05 pm
    Edit report at http://pear.php.net/bugs/bug.php?id=14622&edit=1

    ID: 14622
    Updated by: daniel.oconnor@gmail.com
    Reported By: sharon_correll at sil dot org
    Summary: reading tar files with split filenames needs slash
    inserted
    Status: Assigned
    Type: Bug
    Package: File_Archive
    Operating System: Windows XP
    Package Version: 1.5.4
    PHP Version: 5.2.5
    Assigned To: doconnor
    Roadmap Versions:
    New Comment:

    Bug #10144


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

    [2010-09-06 15:03:38] doconnor

    -Assigned To:
    +Assigned To: doconnor


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

    [2008-10-10 12:39:10] sharoncorrell

    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" );
    }

    ?>

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

    [2008-10-09 09:56:59] doconnor

    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-09-08 18:17:11] sharoncorrell

    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.
    }

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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedSep 6, '10 at 3:03p
activeSep 6, '10 at 3:05p
posts2
users1
websitepear.php.net

1 user in discussion

Daniel Oconnor: 2 posts

People

Translate

site design / logo © 2022 Grokbase