add a fuzzing target for the parser

This commit is contained in:
KodrAus 2021-11-02 09:46:18 +10:00
parent 9d06072aa5
commit 4b30c32ca8
8 changed files with 49 additions and 0 deletions

View File

@ -118,6 +118,10 @@ You can follow [this link][lrus] to look for issues like this.
[lrus]: https://github.com/uuid-rs/uuid/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-asc
# Fuzzing
We use [`cargo fuzz`] to fuzz test various parts of `uuid`. See their guide
for more details on what fuzzing is and how to run the tests yourself.
# Helpful Links
[Helpful Links]: #helpful-links
@ -133,3 +137,4 @@ seasoned developers, some useful places to look for information are:
[u-r-l-o]: https://users.rust-lang.org
[Discussions]: https://github.com/uuid-rs/uuid/discussions
[search existing issues]: https://github.com/uuid-rs/uuid/search?q=&type=Issues&utf8=%E2%9C%93
[`cargo fuzz`]: https://rust-fuzz.github.io/book/cargo-fuzz.html

3
fuzz/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
target
corpus
artifacts

25
fuzz/Cargo.toml Normal file
View File

@ -0,0 +1,25 @@
[package]
name = "uuid-fuzz"
version = "0.0.0"
authors = ["Automatically generated"]
publish = false
edition = "2018"
[package.metadata]
cargo-fuzz = true
[dependencies]
libfuzzer-sys = "0.4"
[dependencies.uuid]
path = ".."
# Prevent this from interfering with workspaces
[workspace]
members = ["."]
[[bin]]
name = "fuzz_target_parse"
path = "fuzz_targets/fuzz_target_parse.rs"
test = false
doc = false

View File

@ -0,0 +1 @@
{6d93bade-bd9f-4e13-8914-9474e1e3567b}

View File

@ -0,0 +1 @@
67e55044-10b1-426f-9247-bb680e5fe0c8

View File

@ -0,0 +1 @@
67e5504410b1426f9247bb680e5fe0c8

View File

@ -0,0 +1 @@
urn:uuid:67e55044-10b1-426f-9247-bb680e5fe0c8

View File

@ -0,0 +1,12 @@
#![no_main]
use libfuzzer_sys::fuzz_target;
use std::str;
use uuid::Uuid;
fuzz_target!(|data: &[u8]| {
if let Ok(uuid) = str::from_utf8(data) {
// Ensure the parser doesn't panic
let _ = Uuid::parse_str(uuid);
}
});