Fixed handling of ustar tar files with long names.

This commit is contained in:
Strachu
2014-12-15 21:13:57 +01:00
parent f72558de9e
commit 2e533f9fb5
3 changed files with 17 additions and 1 deletions

View File

@@ -40,6 +40,22 @@ namespace SharpCompress.Test
}
}
[TestMethod]
public void Tar_UstarArchivePathReadLongName()
{
string unmodified = Path.Combine(TEST_ARCHIVES_PATH, "ustar with long names.tar");
using(var archive = TarArchive.Open(unmodified))
{
Assert.AreEqual(6, archive.Entries.Count);
Assert.IsTrue(archive.Entries.Any(entry => entry.Key == "Directory/"));
Assert.IsTrue(archive.Entries.Any(entry => entry.Key == "Directory/Some file with veeeeeeeeeery loooooooooong name"));
Assert.IsTrue(archive.Entries.Any(entry => entry.Key == "Directory/Directory with veeeeeeeeeery loooooooooong name/"));
Assert.IsTrue(archive.Entries.Any(entry => entry.Key == "Directory/Directory with veeeeeeeeeery loooooooooong name/Some file with veeeeeeeeeery loooooooooong name"));
Assert.IsTrue(archive.Entries.Any(entry => entry.Key == "Directory/Directory with veeeeeeeeeery loooooooooong name/Directory with veeeeeeeeeery loooooooooong name/"));
Assert.IsTrue(archive.Entries.Any(entry => entry.Key == "Directory/Directory with veeeeeeeeeery loooooooooong name/Directory with veeeeeeeeeery loooooooooong name/Some file with veeeeeeeeeery loooooooooong name"));
}
}
[TestMethod]
public void Tar_Create_New()
{

View File

@@ -120,7 +120,7 @@ namespace SharpCompress.Common.Tar.Headers
Magic = ArchiveEncoding.Default.GetString(buffer, 257, 6).TrimNulls();
if (!string.IsNullOrEmpty(Magic) && "ustar ".Equals(Magic))
if (!string.IsNullOrEmpty(Magic) && "ustar".Equals(Magic))
{
string namePrefix = ArchiveEncoding.Default.GetString(buffer, 345, 157);
namePrefix = namePrefix.TrimNulls();

Binary file not shown.