lighthouse/eth2/utils/ssz/fuzz/fuzz_targets/fuzz_target_u16.rs
2019-02-20 15:03:32 +11:00

20 lines
549 B
Rust

#![no_main]
#[macro_use] extern crate libfuzzer_sys;
extern crate ssz;
use ssz::{DecodeError, Decodable, Encodable};
// Fuzz ssz_decode(u8)
fuzz_target!(|data: &[u8]| {
let result: Result<(u16, usize), DecodeError> = Decodable::ssz_decode(data, 0);
if data.len() > 1 {
// Valid result
let (number_u16, index) = result.unwrap();
assert_eq!(index, 2);
// TODO: add test for number?
} else {
// Length of 0 or 1 should return error
assert_eq!(result, Err(DecodeError::TooShort));
}
});