decode ipld cargo fuzz harness

This commit is contained in:
Evan Richter 2022-08-09 17:07:10 -05:00
parent 275b7615b8
commit f5bbdcb8a2
No known key found for this signature in database
3 changed files with 45 additions and 0 deletions

4
fuzz/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
target
corpus
artifacts
coverage

28
fuzz/Cargo.toml Normal file
View File

@ -0,0 +1,28 @@
[package]
name = "ipfs-fuzz"
version = "0.0.0"
publish = false
edition = "2018"
[package.metadata]
cargo-fuzz = true
[dependencies]
libfuzzer-sys = "0.4"
cid = "*"
[dependencies.ipfs]
path = ".."
# Prevent this from interfering with workspaces
[workspace]
members = ["."]
[profile.release]
debug = 1
[[bin]]
name = "decode_ipld"
path = "fuzz_targets/decode_ipld.rs"
test = false
doc = false

View File

@ -0,0 +1,13 @@
#![no_main]
use libfuzzer_sys::fuzz_target;
use std::convert::TryFrom;
fuzz_target!(|data: (&str, &[u8])| {
let _ = fuzz(data.0, data.1);
});
fn fuzz(cid: &str, payload: &[u8]) -> Result<(), ()> {
let cid = ipfs::Cid::try_from(cid).map_err(drop)?;
let _ = ipfs::ipld::decode_ipld(&cid, payload).map_err(drop)?;
Ok(())
}