@@ -77,7 +77,21 @@ fn run(input: &[u8]) -> Corpus {
77
77
stream. next_out = output. as_mut_ptr ( ) ;
78
78
stream. avail_out = output. len ( ) . try_into ( ) . unwrap ( ) ;
79
79
80
+ // Small enough to hit interesting cases, but large enough to hit the fast path
80
81
let chunk_size = 64 ;
82
+
83
+ // For code coverage (on CI), we want to keep inputs that triggered the error
84
+ // branches, to get an accurate picture of what error paths we actually hit.
85
+ //
86
+ // It helps that on CI we start with a corpus of valid files: a mutation of such an
87
+ // input is not a sequence of random bytes, but rather quite close to correct and
88
+ // hence likely to hit interesting error conditions.
89
+ let invalid_input = if cfg ! ( feature = "keep-invalid-in-corpus" ) {
90
+ Corpus :: Keep
91
+ } else {
92
+ Corpus :: Reject
93
+ } ;
94
+
81
95
for chunk in input. chunks ( chunk_size) {
82
96
stream. next_in = chunk. as_ptr ( ) as * mut u8 ;
83
97
stream. avail_in = chunk. len ( ) as _ ;
@@ -100,32 +114,15 @@ fn run(input: &[u8]) -> Corpus {
100
114
}
101
115
_ => {
102
116
unsafe { inflateEnd ( & mut stream) } ;
103
-
104
- // For code coverage (on CI), we want to keep inputs that triggered the error
105
- // branches, to get an accurate picture of what error paths we actually hit.
106
- //
107
- // It helps that on CI we start with a corpus of valid files: a mutation of such an
108
- // input is not a sequence of random bytes, but rather quite close to correct and
109
- // hence likely to hit interesting error conditions.
110
- if cfg ! ( feature = "keep-invalid-in-corpus" ) {
111
- return Corpus :: Keep ;
112
- } else {
113
- return Corpus :: Reject ;
114
- }
117
+ return invalid_input;
115
118
}
116
119
}
117
120
}
118
121
119
122
let err = unsafe { inflateEnd ( & mut stream) } ;
120
123
match ReturnCode :: from ( err) {
121
124
ReturnCode :: Ok => Corpus :: Keep ,
122
- _ => {
123
- if cfg ! ( feature = "keep-invalid-in-corpus" ) {
124
- return Corpus :: Keep ;
125
- } else {
126
- return Corpus :: Reject ;
127
- }
128
- }
125
+ _ => invalid_input,
129
126
}
130
127
}
131
128
0 commit comments