Skip to content

Commit

Permalink
Add repro for icsharpcode#229
Browse files Browse the repository at this point in the history
  • Loading branch information
piksel committed Jun 17, 2018
1 parent 97044a6 commit a162df7
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
<None Update="Repros\Samples\Repro218\_GameMeshTri1_color.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Repros\Samples\Repro229\afmlsxmio-bad.zip">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Repros\Samples\Repro229\afmlsxmio-good.zip">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Repros\Samples\Repro229\afmlsxmio.zip">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
82 changes: 82 additions & 0 deletions ICSharpCode.SharpZipLib.ReproTester/Repros/Repro229.cs
Original file line number Diff line number Diff line change
@@ -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)");
}
}
}
}
Git LFS file not shown
Git LFS file not shown

0 comments on commit a162df7

Please sign in to comment.