Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/SharpCompress/Common/Tar/Headers/TarHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private static void WriteStringBytes(string name, byte[] buffer, int offset, int
{
int i;

for (i = 0; i < length - 1 && i < name.Length; ++i)
for (i = 0; i < length && i < name.Length; ++i)
{
buffer[offset + i] = (byte)name[i];
}
Expand Down Expand Up @@ -272,4 +272,4 @@ internal static int RecalculateAltChecksum(byte[] buf)

public string Magic { get; set; }
}
}
}
33 changes: 33 additions & 0 deletions tests/SharpCompress.Test/Tar/TarArchiveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,40 @@ public void TarArchivePathRead()
{
ArchiveFileRead("Tar.tar");
}

[Fact]
public void Tar_FileName_Exactly_100_Characters()
{
string archive = "Tar_FileName_Exactly_100_Characters.tar";


// create the 100 char filename
string filename = "filename_with_exactly_100_characters_______________________________________________________________X";

// Step 1: create a tar file containing a file with the test name
using (Stream stream = File.OpenWrite(Path.Combine(SCRATCH2_FILES_PATH, archive)))
using (var writer = WriterFactory.Open(stream, ArchiveType.Tar, CompressionType.None))
using (Stream inputStream = new MemoryStream())
{
StreamWriter sw = new StreamWriter(inputStream);
sw.Write("dummy filecontent");
sw.Flush();

inputStream.Position = 0;
writer.Write(filename, inputStream, null);
}

// Step 2: check if the written tar file can be read correctly
string unmodified = Path.Combine(SCRATCH2_FILES_PATH, archive);
using (var archive2 = TarArchive.Open(unmodified))
{
Assert.Equal(1, archive2.Entries.Count);
Assert.Contains(filename, archive2.Entries.Select(entry => entry.Key));

foreach (var entry in archive2.Entries)
Assert.Equal("dummy filecontent", new StreamReader(entry.OpenEntryStream()).ReadLine());
}
}

[Fact]
public void Tar_NonUstarArchiveWithLongNameDoesNotSkipEntriesAfterTheLongOne()
Expand Down