Add fuzz target for CBOR

This commit is contained in:
mingxguo27
2020-08-11 09:48:44 +00:00
parent dcc5d58da9
commit 1e9da1e2d6
2 changed files with 46 additions and 0 deletions

View File

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

View File

@@ -0,0 +1,20 @@
#![no_main]
#[macro_use]
extern crate libfuzzer_sys;
extern crate cbor;
extern crate alloc;
use alloc::vec::Vec;
fuzz_target!(|data: &[u8]| {
let encoded = cbor::read(data);
match encoded{
Ok(value) => {
let mut decoded = Vec::new();
let _ = cbor::write(value, &mut decoded);
assert_eq!(decoded, data);
}
Err(_) => {}
};
});