Merge pull request #737 from Erior/feature/TarHeaderFactory-Infinite-loop

Check for broken file #736
This commit is contained in:
Adam Hathcock
2023-03-30 11:35:20 +01:00
committed by GitHub
3 changed files with 24 additions and 1 deletions

View File

@@ -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");
}
}
}
}

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Linq;
using SharpCompress.Archives;

View File

@@ -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()