From a162df78049a03584825578e5b92e604a627d54b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nils=20m=C3=A5s=C3=A9n?= Date: Sat, 16 Jun 2018 19:51:49 +0200 Subject: [PATCH] Add repro for #229 --- ...ICSharpCode.SharpZipLib.ReproTester.csproj | 9 ++ .../Repros/Repro229.cs | 82 +++++++++++++++++++ .../Repros/Samples/Repro229/afmlsxmio-bad.zip | 3 + .../Samples/Repro229/afmlsxmio-good.zip | 3 + 4 files changed, 97 insertions(+) create mode 100644 ICSharpCode.SharpZipLib.ReproTester/Repros/Repro229.cs create mode 100644 ICSharpCode.SharpZipLib.ReproTester/Repros/Samples/Repro229/afmlsxmio-bad.zip create mode 100644 ICSharpCode.SharpZipLib.ReproTester/Repros/Samples/Repro229/afmlsxmio-good.zip diff --git a/ICSharpCode.SharpZipLib.ReproTester/ICSharpCode.SharpZipLib.ReproTester.csproj b/ICSharpCode.SharpZipLib.ReproTester/ICSharpCode.SharpZipLib.ReproTester.csproj index 1a74110d5..2f6dc81ae 100644 --- a/ICSharpCode.SharpZipLib.ReproTester/ICSharpCode.SharpZipLib.ReproTester.csproj +++ b/ICSharpCode.SharpZipLib.ReproTester/ICSharpCode.SharpZipLib.ReproTester.csproj @@ -28,6 +28,15 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + diff --git a/ICSharpCode.SharpZipLib.ReproTester/Repros/Repro229.cs b/ICSharpCode.SharpZipLib.ReproTester/Repros/Repro229.cs new file mode 100644 index 000000000..594085237 --- /dev/null +++ b/ICSharpCode.SharpZipLib.ReproTester/Repros/Repro229.cs @@ -0,0 +1,82 @@ +using ICSharpCode.SharpZipLib.Zip; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Net; +using System.Net.Http; +using System.Text; +using ICSharpCode.SharpZipLib.BZip2; + +namespace ICSharpCode.SharpZipLib.ReproTester.Repros +{ + [Timeout(minutes: 1)] + internal class Repro229 : Repro + { + string inputGood; + string inputBad; + + public Repro229() + { + inputGood = GetSampleInput("afmlsxmio-good.zip", "zip"); + inputBad = GetSampleInput("afmlsxmio-bad.zip", "zip"); + } + + internal override void Run() + { + Console.WriteLine("GOOD:"); + TestFile(inputGood); + + Console.WriteLine("BAD:"); + TestFile(inputBad); + } + + internal void TestFile(string inputFile) + { + var entryPrinted = false; + var _c = Stopwatch.StartNew(); + + Console.Write("Opening file... "); + using (var fs = File.Open(inputFile, FileMode.Open, FileAccess.Read)) + using(var zf = new ZipFile(fs)) + { + var maxBytes = 1100000; + Console.WriteLine($" {_c.ElapsedMilliseconds:f0}ms"); + + void testCallback(TestStatus s, string m) + { + if (s.BytesTested > maxBytes) + throw new Exception($"Tested bytes exceeds maximum ({maxBytes} bytes)"); + + if(s.Operation == TestOperation.Complete) + { + ConsoleWriter.Write("Test OK", ConsoleColor.Green).End(); + } + if(!string.IsNullOrEmpty(m)) + { + if(s.ErrorCount > 0) + { + throw new Exception(m); + } + else + { + Console.WriteLine(m); + } + } + if (!entryPrinted && s.Entry is ZipEntry e) + { + Console.WriteLine($"Entry #{e.ZipFileIndex} {e.Name}"); + Console.WriteLine($" Size: {e.Size} byte(s) uncompressed, {e.CompressedSize} byte(s) compressed."); + Console.WriteLine($" CRC: {(e.HasCrc ? e.Crc : 0):x8} "); + Console.WriteLine($" Version: {e.Version}, {(e.VersionMadeBy / 2.0):f1} "); + entryPrinted = true; + } + } + Console.WriteLine("Testing archive WITH low level CRC check..."); + _c.Restart(); + var status = zf.TestArchive(true, TestStrategy.FindFirstError, testCallback); + Console.WriteLine($"Testing done, status: {(status ? "OK" : "Failed")} ({_c.ElapsedMilliseconds:f0}ms)"); + } + } + } +} diff --git a/ICSharpCode.SharpZipLib.ReproTester/Repros/Samples/Repro229/afmlsxmio-bad.zip b/ICSharpCode.SharpZipLib.ReproTester/Repros/Samples/Repro229/afmlsxmio-bad.zip new file mode 100644 index 000000000..d30385a55 --- /dev/null +++ b/ICSharpCode.SharpZipLib.ReproTester/Repros/Samples/Repro229/afmlsxmio-bad.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cd9d8d6d98235d62c8d61e9c7d434836b02cf7f8cb1c7140c366723fa60cc02b +size 9216 diff --git a/ICSharpCode.SharpZipLib.ReproTester/Repros/Samples/Repro229/afmlsxmio-good.zip b/ICSharpCode.SharpZipLib.ReproTester/Repros/Samples/Repro229/afmlsxmio-good.zip new file mode 100644 index 000000000..9095c212d --- /dev/null +++ b/ICSharpCode.SharpZipLib.ReproTester/Repros/Samples/Repro229/afmlsxmio-good.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f432059f2154506fb54186b96bf1d9854767916404c76b88199f284c36ebd73a +size 8743