File tree 1 file changed +54
-0
lines changed
test/ICSharpCode.SharpZipLib.Tests/Zip
1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . IO ;
3
+ using System . Text ;
4
+ using System . Threading ;
5
+ using ICSharpCode . SharpZipLib ;
6
+ using ICSharpCode . SharpZipLib . Zip ;
7
+ using NUnit . Framework ;
8
+
9
+ namespace ICSharpCode . SharpZipLib . Tests . Zip
10
+ {
11
+ public class ZipCorruptionHandling
12
+ {
13
+
14
+ const string TestFileZeroCodeLength = "UEsDBBQA+AAIANwyZ0U5T8HwjQAAAL8AAAAIABUAbGltZXJpY2t" +
15
+ "VVAkAAzBXXFR6LmBUVXgEAPQB9AEFjTEOwjAQBHu/YkVDg3gHoUaivjgHtmKfI5+D5d9zbndHM6/AldFJQTIJ" +
16
+ "PrVkPOkgce9QlJFi5hr9rhD+cUUvZ9qgnuRuBAtId97Qw0AL1Kbw5h6MykeKdlyWdlWs7OlUdgsodRqKVo0v8" +
17
+ "JWyGWZ6mLpuiii2t2Bl0mZ54QksOIpqXNPATF/eH1BLAQIXAxQAAgAIANxQZ0U5T8HwjQAAAL8AAAAIAA0AAA" +
18
+ "AAAAEAAACggQAAAABsaW1lcgEAQwAAAMgAAAAAAA==" ;
19
+
20
+ [ Test ]
21
+ [ Category ( "Zip" ) ]
22
+ public void ZeroCodeLengthZipFile ( )
23
+ {
24
+ Assert . Throws < SharpZipBaseException > ( ( ) => {
25
+ Exception threadException = null ;
26
+ var testThread = new Thread ( ( ) => {
27
+ try {
28
+ var fileBytes = Convert . FromBase64String ( TestFileZeroCodeLength ) ;
29
+ using ( var ms = new MemoryStream ( fileBytes ) )
30
+ using ( var zip = new ZipInputStream ( ms ) )
31
+ {
32
+ while ( zip . GetNextEntry ( ) != null ) { }
33
+ }
34
+ }
35
+ catch ( Exception x ) {
36
+ threadException = x ;
37
+ }
38
+ } ) ;
39
+
40
+ testThread . Start ( ) ;
41
+
42
+ if ( ! testThread . Join ( 5000 ) ) {
43
+ testThread . Abort ( ) ;
44
+ throw new TimeoutException ( "Timed out waiting for GetNextEntry() to return" ) ;
45
+ }
46
+ else if ( threadException != null ) {
47
+ throw threadException ;
48
+ }
49
+ } ) ;
50
+ }
51
+
52
+ }
53
+
54
+ }
You can’t perform that action at this time.
0 commit comments