12 my $CompressClass = identify();
13 my $UncompressClass = getInverse($CompressClass);
14 my $Error = getErrorRef($CompressClass);
15 my $UnError = getErrorRef($UncompressClass);
20 #some more stuff on this line
24 # ASCII hex equivalent of the text above. This makes the test
25 # harness behave identically on an EBCDIC platform.
27 "\x68\x65\x6c\x6c\x6f\x20\x77\x6f\x72\x6c\x64\x0a\x74\x68\x69\x73" .
28 "\x20\x69\x73\x20\x61\x20\x74\x65\x73\x74\x0a\x73\x6f\x6d\x65\x20" .
29 "\x6d\x6f\x72\x65\x20\x73\x74\x75\x66\x66\x20\x6f\x6e\x20\x74\x68" .
30 "\x69\x73\x20\x6c\x69\x6e\x65\x0a\x61\x6e\x64\x20\x66\x69\x6e\x61" .
31 "\x6c\x6c\x79\x2e\x2e\x2e\x0a" ;
36 my ($info, $compressed) = mkComplete($CompressClass, $hello);
38 my $header_size = $info->{HeaderLength};
39 my $trailer_size = $info->{TrailerLength};
40 my $fingerprint_size = $info->{FingerprintLength};
41 ok 1, "Compressed size is " . length($compressed) ;
42 ok 1, "Fingerprint size is $fingerprint_size" ;
43 ok 1, "Header size is $header_size" ;
44 ok 1, "Trailer size is $trailer_size" ;
46 for my $trans ( 0 .. 1)
48 title "Truncating $CompressClass, Transparent $trans";
51 foreach my $i (1 .. $fingerprint_size-1)
53 my $lex = new LexFile my $name ;
55 title "Fingerprint Truncation - length $i, Transparent $trans";
57 my $part = substr($compressed, 0, $i);
58 writeFile($name, $part);
60 my $gz = new $UncompressClass $name,
61 -BlockSize => $blocksize,
62 -Transparent => $trans;
67 is $gz->read($buff), length($part) ;
79 # Any header corruption past the fingerprint is considered catastrophic
80 # so even if Transparent is set, it should still fail
82 foreach my $i ($fingerprint_size .. $header_size -1)
84 my $lex = new LexFile my $name ;
86 title "Header Truncation - length $i, Transparent $trans";
88 my $part = substr($compressed, 0, $i);
89 writeFile($name, $part);
90 ok ! defined new $UncompressClass $name,
91 -BlockSize => $blocksize,
92 -Transparent => $trans;
97 foreach my $i ($header_size .. length($compressed) - 1 - $trailer_size)
101 my $lex = new LexFile my $name ;
103 title "Compressed Data Truncation - length $i, Transparent $trans";
105 my $part = substr($compressed, 0, $i);
106 writeFile($name, $part);
107 ok my $gz = new $UncompressClass $name,
109 -BlockSize => $blocksize,
110 -Transparent => $trans
115 $status = $gz->read($un) while $status > 0 ;
116 cmp_ok $status, "<", 0 ;
122 # RawDeflate does not have a trailer
123 next if $CompressClass eq 'IO::Compress::RawDeflate' ;
125 title "Compressed Trailer Truncation";
126 foreach my $i (length($compressed) - $trailer_size .. length($compressed) -1 )
128 foreach my $lax (0, 1)
130 my $lex = new LexFile my $name ;
132 ok 1, "Compressed Trailer Truncation - Length $i, Lax $lax, Transparent $trans" ;
133 my $part = substr($compressed, 0, $i);
134 writeFile($name, $part);
135 ok my $gz = new $UncompressClass $name,
136 -BlockSize => $blocksize,
139 -Transparent => $trans;
142 $status = $gz->read($un) while $status > 0 ;
148 or diag "Status $status Error is " . $gz->error() ;
150 or diag "Status $status Error is " . $gz->error() ;
155 cmp_ok $status, "<", 0
156 or diag "Status $status Error is " . $gz->error() ;
158 or diag "Status $status Error is " . $gz->error() ;