diff --git a/src/SharpCompress/Common/Tar/TarEntry.cs b/src/SharpCompress/Common/Tar/TarEntry.cs index 7b5e4a05..59743070 100644 --- a/src/SharpCompress/Common/Tar/TarEntry.cs +++ b/src/SharpCompress/Common/Tar/TarEntry.cs @@ -72,6 +72,10 @@ public class TarEntry : Entry yield return new TarEntry(new TarFilePart(h, null), compressionType); } } + else + { + throw new IncompleteArchiveException("Unexpected EOF reading tar file"); + } } } } diff --git a/tests/SharpCompress.Test/Tar/TarArchiveTests.cs b/tests/SharpCompress.Test/Tar/TarArchiveTests.cs index fd05d15e..dddb32a6 100644 --- a/tests/SharpCompress.Test/Tar/TarArchiveTests.cs +++ b/tests/SharpCompress.Test/Tar/TarArchiveTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Linq; using SharpCompress.Archives; diff --git a/tests/SharpCompress.Test/Tar/TarReaderTests.cs b/tests/SharpCompress.Test/Tar/TarReaderTests.cs index a92a3c0a..76629363 100644 --- a/tests/SharpCompress.Test/Tar/TarReaderTests.cs +++ b/tests/SharpCompress.Test/Tar/TarReaderTests.cs @@ -183,6 +183,25 @@ public class TarReaderTests : ReaderTests } } + [Fact] + public void Tar_Broken_Stream() + { + string archiveFullPath = Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar"); + using (Stream stream = File.OpenRead(archiveFullPath)) + using (IReader reader = ReaderFactory.Open(stream)) + { + var memoryStream = new MemoryStream(); + + Action action = () => reader.MoveToNextEntry(); + var exception = Record.Exception(action); + Assert.Null(exception); + reader.MoveToNextEntry(); + reader.WriteEntryTo(memoryStream); + stream.Close(); + Assert.Throws(action); + } + } + #if !NETFRAMEWORK [Fact] public void Tar_GZip_With_Symlink_Entries()