mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-11-18 02:11:57 +00:00
Merge pull request #737 from Erior/feature/TarHeaderFactory-Infinite-loop
Check for broken file #736
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SharpCompress.Archives;
|
||||
|
||||
@@ -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<IncompleteArchiveException>(action);
|
||||
}
|
||||
}
|
||||
|
||||
#if !NETFRAMEWORK
|
||||
[Fact]
|
||||
public void Tar_GZip_With_Symlink_Entries()
|
||||
|
||||
Reference in New Issue
Block a user