fix(tar): prevent infinite loop when reading corrupted archive

This commit is contained in:
blokyk
2024-04-24 03:13:13 +02:00
parent b203d165f5
commit dbbc7c8132
3 changed files with 17 additions and 0 deletions

View File

@@ -189,6 +189,8 @@ public class TarArchive : AbstractWritableArchive<TarArchiveEntry, TarVolume>
CompressionType.None
);
}
} else {
throw new IncompleteArchiveException("Failed to read TAR header");
}
}
}

View File

@@ -183,6 +183,21 @@ public class TarReaderTests : ReaderTests
Assert.Throws<IncompleteArchiveException>(() => reader.MoveToNextEntry());
}
[Fact]
public void Tar_Corrupted()
{
var archiveFullPath = Path.Combine(TEST_ARCHIVES_PATH, "TarCorrupted.tar");
using Stream stream = File.OpenRead(archiveFullPath);
using var reader = ReaderFactory.Open(stream);
var memoryStream = new MemoryStream();
Assert.True(reader.MoveToNextEntry());
Assert.True(reader.MoveToNextEntry());
reader.WriteEntryTo(memoryStream);
stream.Close();
Assert.Throws<IncompleteArchiveException>(() => reader.MoveToNextEntry());
}
#if !NETFRAMEWORK
[Fact]
public void Tar_GZip_With_Symlink_Entries()

Binary file not shown.