-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
214 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
target | ||
corpus | ||
artifacts |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,23 @@ | ||
[package] | ||
name = "norm-fuzz" | ||
version = "0.0.0" | ||
authors = ["Automatically generated"] | ||
publish = false | ||
edition = "2021" | ||
|
||
[package.metadata] | ||
cargo-fuzz = true | ||
|
||
[dependencies] | ||
norm = { path = "..", features = ["fzf-v1", "fzf-v2"] } | ||
libfuzzer-sys = { version = "0.4", features = ["arbitrary-derive"] } | ||
|
||
# Prevent this from interfering with workspaces | ||
[workspace] | ||
members = ["."] | ||
|
||
[[bin]] | ||
name = "fzf" | ||
path = "fuzz_targets/fzf.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,67 @@ | ||
#![no_main] | ||
|
||
use libfuzzer_sys::arbitrary::{self, Arbitrary}; | ||
use libfuzzer_sys::fuzz_target; | ||
use norm::fzf::{FzfParser, FzfScheme, FzfV1, FzfV2}; | ||
use norm::{CaseSensitivity, Metric}; | ||
|
||
#[derive(Arbitrary, Copy, Clone, Debug)] | ||
struct Query<'a>(&'a str); | ||
|
||
#[derive(Arbitrary, Clone, Debug)] | ||
struct Candidate<'a>(&'a str); | ||
|
||
fn with_opts<F>(mut fun: F) | ||
where | ||
F: FnMut(CaseSensitivity, bool, FzfScheme), | ||
{ | ||
for case_sensitivity in [ | ||
CaseSensitivity::Sensitive, | ||
CaseSensitivity::Insensitive, | ||
CaseSensitivity::Smart, | ||
] { | ||
for normalization in [true, false] { | ||
for scheme in | ||
[FzfScheme::Default, FzfScheme::Path, FzfScheme::History] | ||
{ | ||
fun(case_sensitivity, normalization, scheme) | ||
} | ||
} | ||
} | ||
} | ||
|
||
fuzz_target!(|data: (Query, Candidate)| { | ||
let (Query(query), Candidate(candidate)) = data; | ||
|
||
let mut parser = FzfParser::new(); | ||
|
||
let query = parser.parse(query); | ||
|
||
let mut fzf_v1 = FzfV1::new(); | ||
|
||
let mut fzf_v2 = FzfV2::new(); | ||
|
||
with_opts(|case_sensitivity, normalization, scheme| { | ||
fzf_v1 = core::mem::take(&mut fzf_v1) | ||
.with_case_sensitivity(case_sensitivity) | ||
.with_normalization(normalization) | ||
.with_scoring_scheme(scheme); | ||
|
||
if let Some(mach) = fzf_v1.distance(query, candidate) { | ||
for range in mach.matched_ranges() { | ||
let _s = &candidate[range.clone()]; | ||
} | ||
} | ||
|
||
fzf_v2 = core::mem::take(&mut fzf_v2) | ||
.with_case_sensitivity(case_sensitivity) | ||
.with_normalization(normalization) | ||
.with_scoring_scheme(scheme); | ||
|
||
if let Some(mach) = fzf_v2.distance(query, candidate) { | ||
for range in mach.matched_ranges() { | ||
let _s = &candidate[range.clone()]; | ||
} | ||
} | ||
}); | ||
}); |