Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for broken file #736 #737

Merged
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: 4 additions & 0 deletions src/SharpCompress/Common/Tar/TarEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ ArchiveEncoding archiveEncoding
yield return new TarEntry(new TarFilePart(h, null), compressionType);
}
}
else
{
throw new IncompleteArchiveException("Unexpected EOF reading tar file");
}
}
}
}
2 changes: 1 addition & 1 deletion tests/SharpCompress.Test/Tar/TarArchiveTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Linq;
using SharpCompress.Archives;
Expand Down
19 changes: 19 additions & 0 deletions tests/SharpCompress.Test/Tar/TarReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,25 @@ public void Tar_With_TarGz_With_Flushed_EntryStream()
}
}

[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<IncompleteArchiveException>(action);
}
}

#if !NETFRAMEWORK
[Fact]
public void Tar_GZip_With_Symlink_Entries()
Expand Down