Skip to content

Commit c518975

Browse files
authored
Merge pull request #60 from fitzgen/early-exit-on-too-few-bytes
Early exit when given too few bytes for the `Arbitrary` impl
2 parents ff648be + 90c1140 commit c518975

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ macro_rules! fuzz_target {
143143
pub extern "C" fn rust_fuzzer_test_input(bytes: &[u8]) {
144144
use libfuzzer_sys::arbitrary::{Arbitrary, Unstructured};
145145

146+
// Early exit if we don't have enough bytes for the `Arbitrary`
147+
// implementation. This helps the fuzzer avoid exploring all the
148+
// different not-enough-input-bytes paths inside the `Arbitrary`
149+
// implementation. Additionally, it exits faster, letting the fuzzer
150+
// get to longer inputs that actually lead to interesting executions
151+
// quicker.
152+
if bytes.len() < <$dty as Arbitrary>::size_hint(0).0 {
153+
return;
154+
}
155+
146156
let mut u = Unstructured::new(bytes);
147157
let data = <$dty as Arbitrary>::arbitrary_take_rest(u);
148158

0 commit comments

Comments
 (0)