Add fuzz target for CBOR
This commit is contained in:
26
libraries/cbor/fuzz/Cargo.toml
Normal file
26
libraries/cbor/fuzz/Cargo.toml
Normal 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
|
||||
20
libraries/cbor/fuzz/fuzz_targets/fuzz_target_1.rs
Normal file
20
libraries/cbor/fuzz/fuzz_targets/fuzz_target_1.rs
Normal 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(_) => {}
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user