From 13263c9f81e72f04c99d0c54c0c190fe79077f70 Mon Sep 17 00:00:00 2001 From: Martin Geisler Date: Sun, 30 Oct 2022 10:21:11 +0100 Subject: [PATCH] Limit inputs to prevent OSS-Fuzz timeouts I downloaded the failing test cases from OSS-Fuzz and ran the fuzzers on each of them: they all finished in ~35 seconds on my laptop. The timeout on OSS-Fuzz is 25 seconds, which explains the timeouts. Limiting the input length to 100k bytes should help here and still allow us to test all reasonable inputs. --- fuzz/fuzz_targets/fill_fast_path.rs | 4 ++++ fuzz/fuzz_targets/fill_first_fit.rs | 4 ++++ fuzz/fuzz_targets/fill_optimal_fit.rs | 4 ++++ fuzz/fuzz_targets/refill.rs | 4 ++++ fuzz/fuzz_targets/unfill.rs | 4 ++++ fuzz/fuzz_targets/wrap_fast_path.rs | 10 ++++++---- 6 files changed, 26 insertions(+), 4 deletions(-) diff --git a/fuzz/fuzz_targets/fill_fast_path.rs b/fuzz/fuzz_targets/fill_fast_path.rs index 31966120..cdffc22c 100644 --- a/fuzz/fuzz_targets/fill_fast_path.rs +++ b/fuzz/fuzz_targets/fill_fast_path.rs @@ -2,6 +2,10 @@ use libfuzzer_sys::fuzz_target; fuzz_target!(|input: (String, usize)| { + if input.0.len() > 100_000 { + return; // Avoid timeouts in OSS-Fuzz. + } + let options = textwrap::Options::new(input.1); let fast = textwrap::fill(&input.0, &options); let slow = textwrap::fuzzing::fill_slow_path(&input.0, options); diff --git a/fuzz/fuzz_targets/fill_first_fit.rs b/fuzz/fuzz_targets/fill_first_fit.rs index fe44367f..8fb58307 100644 --- a/fuzz/fuzz_targets/fill_first_fit.rs +++ b/fuzz/fuzz_targets/fill_first_fit.rs @@ -4,6 +4,10 @@ use textwrap::Options; use textwrap::WrapAlgorithm; fuzz_target!(|input: (String, usize)| { + if input.0.len() > 100_000 { + return; // Avoid timeouts in OSS-Fuzz. + } + let options = Options::new(input.1).wrap_algorithm(WrapAlgorithm::FirstFit); let _ = textwrap::fill(&input.0, &options); }); diff --git a/fuzz/fuzz_targets/fill_optimal_fit.rs b/fuzz/fuzz_targets/fill_optimal_fit.rs index 4465eac2..b0452152 100644 --- a/fuzz/fuzz_targets/fill_optimal_fit.rs +++ b/fuzz/fuzz_targets/fill_optimal_fit.rs @@ -4,6 +4,10 @@ use textwrap::Options; use textwrap::WrapAlgorithm; fuzz_target!(|input: (String, usize)| { + if input.0.len() > 100_000 { + return; // Avoid timeouts in OSS-Fuzz. + } + let options = Options::new(input.1).wrap_algorithm(WrapAlgorithm::new_optimal_fit()); let _ = textwrap::fill(&input.0, &options); }); diff --git a/fuzz/fuzz_targets/refill.rs b/fuzz/fuzz_targets/refill.rs index 16073d0d..a45e6159 100644 --- a/fuzz/fuzz_targets/refill.rs +++ b/fuzz/fuzz_targets/refill.rs @@ -2,5 +2,9 @@ use libfuzzer_sys::fuzz_target; fuzz_target!(|input: (String, usize)| { + if input.0.len() > 100_000 { + return; // Avoid timeouts in OSS-Fuzz. + } + let _ = textwrap::refill(&input.0, input.1); }); diff --git a/fuzz/fuzz_targets/unfill.rs b/fuzz/fuzz_targets/unfill.rs index f9a1bfb3..ad0b49b7 100644 --- a/fuzz/fuzz_targets/unfill.rs +++ b/fuzz/fuzz_targets/unfill.rs @@ -2,5 +2,9 @@ use libfuzzer_sys::fuzz_target; fuzz_target!(|input: String| { + if input.len() > 100_000 { + return; // Avoid timeouts in OSS-Fuzz. + } + let _ = textwrap::unfill(&input); }); diff --git a/fuzz/fuzz_targets/wrap_fast_path.rs b/fuzz/fuzz_targets/wrap_fast_path.rs index 8a2ca84e..acc65b53 100644 --- a/fuzz/fuzz_targets/wrap_fast_path.rs +++ b/fuzz/fuzz_targets/wrap_fast_path.rs @@ -2,15 +2,17 @@ use libfuzzer_sys::fuzz_target; fuzz_target!(|input: (String, usize)| { - // Filter out multi-line input. + if input.0.len() > 100_000 { + return; // Avoid timeouts in OSS-Fuzz. + } + if input.0.contains('\n') { - return; + return; // Filter out multi-line input. } + let options = textwrap::Options::new(input.1); let mut fast = Vec::new(); let mut slow = Vec::new(); - - let options = textwrap::Options::new(input.1); textwrap::fuzzing::wrap_single_line(&input.0, &options, &mut fast); textwrap::fuzzing::wrap_single_line_slow_path(&input.0, &options, &mut slow); assert_eq!(fast, slow);