Skip to content

Commit ec138b9

Browse files
committed
Add repro for icsharpcode#121 (and icsharpcode#182)
1 parent 0f0c67f commit ec138b9

18 files changed

+204
-12
lines changed

ICSharpCode.SharpZipLib.ReproTester/ICSharpCode.SharpZipLib.ReproTester.csproj

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,36 @@
1919
<None Update="Repros\Samples\Repro118\aaa16.zip">
2020
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2121
</None>
22+
<None Update="Repros\Samples\Repro121\lftest-gnu.tar">
23+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
24+
</None>
25+
<None Update="Repros\Samples\Repro121\lftest-oldgnu.tar">
26+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
27+
</None>
28+
<None Update="Repros\Samples\Repro121\lftest-posix.tar">
29+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
30+
</None>
31+
<None Update="Repros\Samples\Repro121\lftest-ustar.tar">
32+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
33+
</None>
34+
<None Update="Repros\Samples\Repro121\lftest-v7.tar">
35+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
36+
</None>
37+
<None Update="Repros\Samples\Repro121\utf8test-gnu.tar">
38+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
39+
</None>
40+
<None Update="Repros\Samples\Repro121\utf8test-oldgnu.tar">
41+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
42+
</None>
43+
<None Update="Repros\Samples\Repro121\utf8test-posix.tar">
44+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
45+
</None>
46+
<None Update="Repros\Samples\Repro121\utf8test-ustar.tar">
47+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
48+
</None>
49+
<None Update="Repros\Samples\Repro121\utf8test-v7.tar">
50+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
51+
</None>
2252
<None Update="Repros\Samples\Repro204\test.tar.gz">
2353
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2454
</None>

ICSharpCode.SharpZipLib.ReproTester/Program.cs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,24 @@ static class Program
1818
public static string WorkRoot => workRoot;
1919

2020
static void Main()
21+
{
22+
Setup();
23+
24+
//Run<Repro229>();
25+
//Run<Repro218>();
26+
//Run<Repro213>();
27+
//Run<Repro204>();
28+
//Run<Repro118>();
29+
//Run<Repro208>();
30+
Run<Repro121>();
31+
32+
//RunAll();
33+
34+
Console.Write("Press any key to exit... ");
35+
Console.ReadKey();
36+
}
37+
38+
private static void Setup()
2139
{
2240
Console.Title = "SharpZipLib Repro Tester";
2341
Console.ForegroundColor = ConsoleColor.White;
@@ -41,18 +59,6 @@ static void Main()
4159
}
4260

4361
Directory.CreateDirectory(workRoot);
44-
45-
Run<Repro229>();
46-
//Run<Repro218>();
47-
//Run<Repro213>();
48-
//Run<Repro204>();
49-
//Run<Repro118>();
50-
//Run<Repro208>();
51-
52-
//RunAll();
53-
54-
Console.Write("Press any key to exit... ");
55-
Console.ReadKey();
5662
}
5763

5864
private static void RunAll()
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
using ICSharpCode.SharpZipLib.Tar;
2+
using ICSharpCode.SharpZipLib.Zip;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Diagnostics;
6+
using System.IO;
7+
using System.Linq;
8+
using System.Net;
9+
using System.Text;
10+
11+
namespace ICSharpCode.SharpZipLib.ReproTester.Repros
12+
{
13+
internal class Repro121 : Repro
14+
{
15+
readonly string[] FileFormats = new [] { "gnu", "oldgnu", "v7", "ustar", "posix" };
16+
17+
private readonly (string Format, string FileUtf8, string FileLongName)[] testFiles;
18+
19+
const string LongFileNameGood = "lftest-0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999";
20+
const string Utf8FileNameGood = "åäö";
21+
const string Utf8FileNameBad = "åäö";
22+
23+
24+
public Repro121()
25+
{
26+
testFiles = FileFormats.Select(f => (
27+
Format: f,
28+
FileUtf8: GetSampleInput($"utf8test-{f}.tar", "tar"),
29+
FileLongName: GetSampleInput($"lftest-{f}.tar", "tar")
30+
)).ToArray();
31+
}
32+
33+
internal override void Run()
34+
{
35+
void LogTestResult(string name, string error)
36+
{
37+
var cw = ConsoleWriter.Write($" {name}: ");
38+
if (error != null)
39+
cw._($"Failed! Error: {error}", ConsoleColor.Red).End();
40+
else
41+
cw._($"OK!", ConsoleColor.Green).End();
42+
}
43+
44+
Console.WriteLine();
45+
46+
foreach (var (Format, FileUtf8, FileLongName) in testFiles)
47+
{
48+
ConsoleWriter.Write($"Testing ")._(Format, ConsoleColor.Cyan)._(" format: ").End();
49+
var utf8error = TestUtf8(Format, FileUtf8);
50+
var lferror = TestLongName(Format, FileLongName);
51+
52+
ConsoleWriter.Write($"Results for ")._(Format, ConsoleColor.Cyan)._(":").End();
53+
LogTestResult("UTF8", utf8error);
54+
LogTestResult("Long file names", lferror);
55+
Console.WriteLine();
56+
}
57+
}
58+
59+
private string TestUtf8(string format, string file)
60+
{
61+
string error = null;
62+
Console.WriteLine($"## Testing {format} UTF8");
63+
64+
using (var fs = File.OpenRead(file))
65+
using (var tis = new TarInputStream(fs))
66+
{
67+
68+
var entry = tis.GetNextEntry();
69+
if (entry == null)
70+
error = "Entry is null";
71+
else if (entry.Name == null)
72+
error = "Entry name is null";
73+
else if (entry.Name == Utf8FileNameBad)
74+
error = $"Entry name matches known bad value";
75+
else if (entry.Name != Utf8FileNameGood)
76+
error = "Entry name does not match expected good value";
77+
78+
ConsoleWriter.Write($"Name: ")._(entry?.Name ?? "(null)", ConsoleColor.Magenta).End();
79+
80+
}
81+
82+
return error;
83+
}
84+
85+
private string TestLongName(string format, string file)
86+
{
87+
string error = null;
88+
Console.WriteLine($"## Testing {format} long filename");
89+
90+
using (var fs = File.OpenRead(file))
91+
using (var tis = new TarInputStream(fs))
92+
{
93+
var entry = tis.GetNextEntry();
94+
95+
if (entry == null)
96+
error = "Entry is null";
97+
else if (entry.Name == null)
98+
error = "Entry name is null";
99+
else if (entry.Name.Length < 107)
100+
error = $"Entry name truncated to {entry.Name.Length} bytes";
101+
else if (entry.Name != LongFileNameGood)
102+
error = "Entry name does not match expected good value";
103+
104+
ConsoleWriter.Write($"Name: ")._(entry?.Name ?? "(null)", ConsoleColor.Magenta).End();
105+
106+
return error;
107+
108+
}
109+
}
110+
}
111+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:06583469ed5c62b75bca558bb19915568350689349ec89988f63d63fd118ec70
3+
size 10240
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:8673d9f7a9b0fe7617302e190118e2cdef5794cbdb3d84dbc9bf0d2be0fb4895
3+
size 10240
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:3f1d2bb129e040be87281817d8edcf8e08039f39c4c064afd4772b4f109609ae
3+
size 10240
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:84ff92691f909a05b224e1c56abb4864f01b4f8e3c854e4bb4c7baf1d3f6d652
3+
size 10240
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:84ff92691f909a05b224e1c56abb4864f01b4f8e3c854e4bb4c7baf1d3f6d652
3+
size 10240
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:440570ff00a17fda0c9edd01d7e81caf1e48e6be423151616e522a198901a883
3+
size 702
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:a808769f04f335536d3da02d5045c72c49a0c616755f57daf6be55085008295f
3+
size 2048

0 commit comments

Comments
 (0)