Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit inputs to prevent OSS-Fuzz timeouts #488

Merged
merged 1 commit into from
Oct 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions fuzz/fuzz_targets/fill_fast_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions fuzz/fuzz_targets/fill_first_fit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
4 changes: 4 additions & 0 deletions fuzz/fuzz_targets/fill_optimal_fit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
4 changes: 4 additions & 0 deletions fuzz/fuzz_targets/refill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
4 changes: 4 additions & 0 deletions fuzz/fuzz_targets/unfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
10 changes: 6 additions & 4 deletions fuzz/fuzz_targets/wrap_fast_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down