Skip to content

Commit 38b1d09

Browse files
committed
cleanup
1 parent 849c614 commit 38b1d09

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

.github/workflows/checks.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ jobs:
290290
- name: Run `cargo fuzz`
291291
env:
292292
RUST_BACKTRACE: "1"
293+
# prevents `cargo fuzz coverage` from rebuilding everything
294+
RUSTFLAGS: "-C instrument-coverage"
293295
run: |
294296
cargo fuzz run ${{matrix.features}} ${{matrix.fuzz_target}} ${{matrix.corpus}} -- -max_total_time=10
295297
- name: Fuzz codecov

fuzz/fuzz_targets/uncompress.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,21 @@ fn run(input: &[u8]) -> Corpus {
7777
stream.next_out = output.as_mut_ptr();
7878
stream.avail_out = output.len().try_into().unwrap();
7979

80+
// Small enough to hit interesting cases, but large enough to hit the fast path
8081
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+
8195
for chunk in input.chunks(chunk_size) {
8296
stream.next_in = chunk.as_ptr() as *mut u8;
8397
stream.avail_in = chunk.len() as _;
@@ -100,32 +114,15 @@ fn run(input: &[u8]) -> Corpus {
100114
}
101115
_ => {
102116
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;
115118
}
116119
}
117120
}
118121

119122
let err = unsafe { inflateEnd(&mut stream) };
120123
match ReturnCode::from(err) {
121124
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,
129126
}
130127
}
131128

0 commit comments

Comments
 (0)