Skip to content

Commit e9da865

Browse files
ros-crfolkertdev
authored andcommitted
Address some PR review comments
1 parent a0e5b81 commit e9da865

File tree

5 files changed

+28
-19
lines changed

5 files changed

+28
-19
lines changed

fuzz/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ rust-allocator = ["libbz2-rs-sys/rust-allocator"]
1818
disable-checksum = ["libbz2-rs-sys/__internal-fuzz-disable-checksum"]
1919
# actively reject and ignore invalid fuzz inputs during processing
2020
# this can have negative effects
21+
# see the README.md for more information
2122
reject-invalid-in-corpus = []
2223

2324
[dependencies.libfuzzer-sys]

fuzz/README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# Fuzz
22

3+
## Corpus input rejection mode
4+
5+
libFuzzer has [an optional mechanism](https://llvm.org/docs/LibFuzzer.html#rejecting-unwanted-inputs) to explicitly reject fuzz inputs.
6+
This directive forces the fuzzer to forget the observed coverage for the current input, and does not allow adding it to the corpus collection.
7+
8+
9+
Use the custom `--features reject-invalid-in-corpus` crate feature to enable this logic in the fuzz harnesses that make use of it. The flag is optional and off by default, see `Cargo.toml`.
10+
11+
This is a heavy-handed approach and reduces fuzzer coverage visibility into the rejected code paths,
12+
but may be useful for time-constrained runs.
13+
14+
Expected effects:
15+
1. reduce some runtime overhead on rejected inputs by skipping post-processing steps
16+
2. increases ratio of "valid" inputs in working corpus
17+
18+
The expectation is that this makes it more likely to create valid inputs by mutation,
19+
at least on short runs with a limited amount of executions that start on a pre-seeded corpus.
20+
321
## Seed corpus
422

523
* https://github.com/trifectatechfoundation/compression-corpus
@@ -8,7 +26,7 @@
826

927
## Fuzzer dictionary
1028

11-
* There is an existing bzip2 format dictionary: https://github.com/google/fuzzing/blob/master/dictionaries/bz2.dict
29+
* There is an existing bzip2 format fuzz dictionary: https://github.com/google/fuzzing/blob/master/dictionaries/bz2.dict
1230
* This could be useful for fuzz tests which consume compressed input and attempt to decompress it
1331
* However, there are only very few common input chunks that bzip2 streams share with each other, so the practical benefits of running the fuzzer with this dictionary is likely limited
1432
* See https://llvm.org/docs/LibFuzzer.html#dictionaries for more background

fuzz/fuzz_targets/compress_then_decompress_chunked.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use libbz2_rs_sys::{
1111

1212
use libfuzzer_sys::fuzz_target;
1313

14+
/// compress the data with the stock C bzip2
1415
fn compress_c(data: &[u8], compression_level: u8, work_factor: u8) -> Vec<u8> {
15-
// compress the data with the stock C bzip2
1616

1717
// output buffer for compression, will get resized later if needed
1818
let mut output = vec![0u8; 1024];

fuzz/fuzz_targets/decompress.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ fuzz_target!(|fuzz_data: &[u8]| {
1212
test_libbz2_rs_sys::decompress_rs_with_capacity(1 << 12, fuzz_data.as_ptr(), fuzz_data.len() as _)
1313
};
1414

15-
// ignore known edge case with different error result behavior
16-
if err_c != -7 && err_rs != -4 {
17-
// in the general case, result codes should be identical
18-
assert_eq!(err_c, err_rs);
19-
}
15+
// result codes between the two implementations should be identical
16+
// previously found https://github.com/trifectatechfoundation/libbzip2-rs/pull/110
17+
assert_eq!(err_c, err_rs);
2018

2119
// if the decompression is successful, the data results should be the same
2220
if err_c == BZ_OK {

fuzz/fuzz_targets/decompress_chunked.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,10 @@ fuzz_target!(|fuzz_data: &[u8]| -> Corpus {
9999
// stop processing
100100
return invalid_input;
101101
}
102-
BZ_FLUSH_OK => {
103-
panic!("BZ_FLUSH_OK");
104-
}
105-
BZ_RUN_OK => {
106-
panic!("BZ_RUN_OK");
107-
}
108-
BZ_FINISH_OK => {
109-
panic!("BZ_FINISH_OK");
110-
}
111-
BZ_OUTBUFF_FULL => {
112-
panic!("BZ_OUTBUFF_FULL");
113-
}
102+
BZ_FLUSH_OK => panic!("BZ_FLUSH_OK"),
103+
BZ_RUN_OK => panic!("BZ_RUN_OK"),
104+
BZ_FINISH_OK => panic!("BZ_FINISH_OK"),
105+
BZ_OUTBUFF_FULL => panic!("BZ_OUTBUFF_FULL"),
114106
err => panic!("{err}"),
115107
}
116108
}

0 commit comments

Comments
 (0)