From 445c1c6eddb282f99b35f295b58db5fa1829584e Mon Sep 17 00:00:00 2001 From: Julien Cretin Date: Thu, 5 Aug 2021 13:37:51 +0200 Subject: [PATCH] Explicitly limit the fuzzer input length This is to avoid timeouts in oss-fuzz. --- libraries/persistent_store/fuzz/src/store.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libraries/persistent_store/fuzz/src/store.rs b/libraries/persistent_store/fuzz/src/store.rs index 006532b..e4e4b4e 100644 --- a/libraries/persistent_store/fuzz/src/store.rs +++ b/libraries/persistent_store/fuzz/src/store.rs @@ -33,7 +33,14 @@ use std::convert::TryInto; /// /// The entropy to generate the sequence of manipulation should be provided in `data`. Debugging /// information is printed if `debug` is set. Statistics are gathered if `stats` is set. -pub fn fuzz(data: &[u8], debug: bool, stats: Option<&mut Stats>) { +pub fn fuzz(mut data: &[u8], debug: bool, stats: Option<&mut Stats>) { + // We limit the input size to avoid timeouts in oss-fuzz because they use inputs of arbitrary + // length and timeout after 1 minute. By default, libFuzzer has a maximum length of 4096 bytes. + // So we just use some number above 4096 bytes and below 1 minute (might need adjustments). + const MAX_DATA_LEN: usize = 10000; + if data.len() > MAX_DATA_LEN { + data = &data[..MAX_DATA_LEN]; + } let mut fuzzer = Fuzzer::new(data, debug, stats); let mut driver = fuzzer.init(); let store = loop {