From a1597cc48b6c1ae5f620c4de4440fa9426e595df Mon Sep 17 00:00:00 2001 From: 5225225 <5225225@mailbox.org> Date: Mon, 25 Sep 2023 15:57:14 +0100 Subject: [PATCH] Add cargo-fuzz fuzzer --- fuzz/.gitignore | 3 +++ fuzz/Cargo.toml | 25 +++++++++++++++++++++++++ fuzz/fuzz_targets/from_bytes.rs | 9 +++++++++ 3 files changed, 37 insertions(+) create mode 100644 fuzz/.gitignore create mode 100644 fuzz/Cargo.toml create mode 100644 fuzz/fuzz_targets/from_bytes.rs diff --git a/fuzz/.gitignore b/fuzz/.gitignore new file mode 100644 index 0000000..a092511 --- /dev/null +++ b/fuzz/.gitignore @@ -0,0 +1,3 @@ +target +corpus +artifacts diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml new file mode 100644 index 0000000..5ba65c0 --- /dev/null +++ b/fuzz/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "serde_bencode-fuzz" +version = "0.0.0" +authors = ["Automatically generated"] +publish = false +edition = "2018" + +[package.metadata] +cargo-fuzz = true + +[dependencies] +libfuzzer-sys = "0.4" + +[dependencies.serde_bencode] +path = ".." + +# Prevent this from interfering with workspaces +[workspace] +members = ["."] + +[[bin]] +name = "from_bytes" +path = "fuzz_targets/from_bytes.rs" +test = false +doc = false diff --git a/fuzz/fuzz_targets/from_bytes.rs b/fuzz/fuzz_targets/from_bytes.rs new file mode 100644 index 0000000..76a46c0 --- /dev/null +++ b/fuzz/fuzz_targets/from_bytes.rs @@ -0,0 +1,9 @@ +#![no_main] +use libfuzzer_sys::fuzz_target; + +use serde_bencode::value::Value; +use serde_bencode::from_bytes; + +fuzz_target!(|data: &[u8]| { + let _: Result = from_bytes(data); +});