1
+ using System ;
2
+ using System . IO ;
3
+ using System . Runtime . InteropServices ;
4
+ using System . Text ;
5
+ using System . Threading ;
6
+ using ICSharpCode . SharpZipLib ;
7
+ using ICSharpCode . SharpZipLib . Zip ;
8
+ using NUnit . Framework ;
9
+
10
+ namespace ICSharpCode . SharpZipLib . Tests . Zip
11
+ {
12
+ public class ZipCorruptionHandling
13
+ {
14
+
15
+ const string TestFileZeroCodeLength = "UEsDBBQA+AAIANwyZ0U5T8HwjQAAAL8AAAAIABUAbGltZXJpY2t" +
16
+ "VVAkAAzBXXFR6LmBUVXgEAPQB9AEFjTEOwjAQBHu/YkVDg3gHoUaivjgHtmKfI5+D5d9zbndHM6/AldFJQTIJ" +
17
+ "PrVkPOkgce9QlJFi5hr9rhD+cUUvZ9qgnuRuBAtId97Qw0AL1Kbw5h6MykeKdlyWdlWs7OlUdgsodRqKVo0v8" +
18
+ "JWyGWZ6mLpuiii2t2Bl0mZ54QksOIpqXNPATF/eH1BLAQIXAxQAAgAIANxQZ0U5T8HwjQAAAL8AAAAIAA0AAA" +
19
+ "AAAAEAAACggQAAAABsaW1lcgEAQwAAAMgAAAAAAA==" ;
20
+
21
+ [ Test ]
22
+ [ Category ( "Zip" ) ]
23
+ public void ZeroCodeLengthZipFile ( )
24
+ {
25
+ Assert . Throws < SharpZipBaseException > ( ( ) => {
26
+ Exception threadException = null ;
27
+ var testThread = new Thread ( ( ) => {
28
+ try {
29
+ var fileBytes = Convert . FromBase64String ( TestFileZeroCodeLength ) ;
30
+ using ( var ms = new MemoryStream ( fileBytes ) )
31
+ using ( var zip = new ZipInputStream ( ms ) )
32
+ {
33
+ while ( zip . GetNextEntry ( ) != null ) { }
34
+ }
35
+ }
36
+ catch ( Exception x ) {
37
+ threadException = x ;
38
+ }
39
+ } ) ;
40
+
41
+ testThread . Start ( ) ;
42
+
43
+ if ( ! testThread . Join ( 5000 ) ) {
44
+ // Aborting threads is deprecated in .NET Core, but if we don't do this,
45
+ // the poor CI will hang for 2 hours upon running this test
46
+ ThreadEx . Abort ( testThread ) ;
47
+ throw new TimeoutException ( "Timed out waiting for GetNextEntry() to return" ) ;
48
+ }
49
+ else if ( threadException != null ) {
50
+ throw threadException ;
51
+ }
52
+ } ) ;
53
+ }
54
+
55
+ }
56
+
57
+ }
0 commit comments