-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce fuzz tests for wrap_optimal_fit and wrap_first_fit
These fuzz tests immediately found the problem reported in #247 and gave a short way of reproducing it: wrap("x y", 515566821223) will currently panic due to an overflow error. The wrap_first_fit function seems to not crash. Run the fuzz tests with: $ cargo fuzz run fill_optimal_fit -- -only_ascii=1 You’ll need to `cargo install cargo-fuzz` first.
- Loading branch information
Showing
5 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
artifacts/ | ||
corpus/ | ||
target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
[package] | ||
name = "textwrap-fuzz" | ||
version = "0.0.0" | ||
authors = ["Automatically generated"] | ||
publish = false | ||
edition = "2018" | ||
|
||
[package.metadata] | ||
cargo-fuzz = true | ||
|
||
[dependencies] | ||
libfuzzer-sys = "0.3" | ||
textwrap = { path = ".." } | ||
|
||
# Prevent this from interfering with workspaces | ||
[workspace] | ||
members = ["."] | ||
|
||
[[bin]] | ||
name = "fill_optimal_fit" | ||
path = "fuzz_targets/fill_optimal_fit.rs" | ||
test = false | ||
doc = false | ||
|
||
[[bin]] | ||
name = "fill_first_fit" | ||
path = "fuzz_targets/fill_first_fit.rs" | ||
test = false | ||
doc = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#![no_main] | ||
use libfuzzer_sys::fuzz_target; | ||
use textwrap::core::WrapAlgorithm::FirstFit; | ||
use textwrap::Options; | ||
|
||
fuzz_target!(|input: (String, usize)| { | ||
let options = Options::new(input.1).wrap_algorithm(FirstFit); | ||
let _ = textwrap::fill(&input.0, &options); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#![no_main] | ||
use libfuzzer_sys::fuzz_target; | ||
use textwrap::core::WrapAlgorithm::OptimalFit; | ||
use textwrap::Options; | ||
|
||
fuzz_target!(|input: (String, usize)| { | ||
let options = Options::new(input.1).wrap_algorithm(OptimalFit); | ||
let _ = textwrap::fill(&input.0, &options); | ||
}); |