PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » File Formats » File_Archive » Bug #10144

long filenames are not stored correctly

Details

Submitted2007-02-21 14:31 UTC
Fromfritsch+pear dot php dot net at in dot tum dot de
Assignedcbrunet
StatusVerified
PackageFile_Archive
PHP VersionIrrelevant
OSUbuntu
Roadmaps1.5.5

Comments

[2007-02-21 14:31 UTC] fritsch+pear dot php dot net at in dot tum dot de

Description:
------------
In Writer/Tar.php it reads like this:
$filePrefix = '';
if (strlen($filename) > 255) {
return PEAR::raiseError(
"$filename is too long to be put in a tar archive"
);
} else if (strlen($filename) > 100) {
$filePrefix = substr($filename, 0, strlen($filename)-100);
$filename = substr($filename, -100);
}

Actually (at least unix tar handles archives like that) the prefix needs to be a path-component, so that "$filePrefix/$filename" is the actual filename. This is not handled correctly by the above code, so it will inject a slash at strlen()-100 for the filename, resulting in really messy tarfiles.

Test script:
---------------
A solution might look like this:
} else if (strlen($filename) > 100) {
#need a path component of max 155 bytes
$pos = strrpos(substr($filename, 0, 155), '/');
if(strlen($filename) - $pos > 100) #filename-component may not exceed 100 bytes
return PEAR::raiseError(
"$filename is too long to be put in a tar archive"
);
$filePrefix = substr($filename, 0, $pos);
$filename = substr($filename, $pos+1);
echo "$filePrefix vs $filename<br>\n";
}