mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-03 21:23:38 +00:00
Incorrect code processing long filename (more than 100 symbols) #30
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @sfairat15 on GitHub (Mar 17, 2015).
Hello.
We get exception when try to add files with names more than 100 symbols. System.ArgumentOutOfRangeException: Index and length must refer to a location within the string.
Parameter name: length
at System.String.Substring(Int32 startIndex, Int32 length)
at SharpCompress.Common.Tar.Headers.TarHeader.Write(Stream output)
Looks like next code is incorrect at TarHeader class
if (Name.Length > 100)
{
name = Name.Substring(101, Name.Length);
ArchiveEncoding.Default.GetBytes(name).CopyTo(buffer, 345);
}
Should be:
name = Name.Substring(101, Name.Length - 100); //??
@sander2 commented on GitHub (Apr 7, 2015):
Actually, that's not quite correct.
There are two fields: the name at byte 0, and the prefix field at byte 345.
The full filepath is <prefix>/<name>. Note the slash between the name and the prefix is implicit; it is neither present in the prefix nor in the name field. This means even when the complete filepath is more than 100 chars long, the name field might not entirely be filled. Therefore, the maximum length of the filepath is dependent on the exact locations of the slashes in the filepath.
I have filed a pull request which makes use of LongLinks instead of the prefix field. This makes arbitrarily long filepaths possible.