PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

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