Fuzz test for u8 fails
This commit is contained in:
parent
52347d8e6d
commit
38abcc4a24
@ -20,3 +20,7 @@ members = ["."]
|
|||||||
[[bin]]
|
[[bin]]
|
||||||
name = "fuzz_target_u8"
|
name = "fuzz_target_u8"
|
||||||
path = "fuzz_targets/fuzz_target_u8.rs"
|
path = "fuzz_targets/fuzz_target_u8.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "fuzz_target_u16"
|
||||||
|
path = "fuzz_targets/fuzz_target_u16.rs"
|
||||||
|
19
eth2/utils/ssz/fuzz/fuzz_targets/fuzz_target_u16.rs
Normal file
19
eth2/utils/ssz/fuzz/fuzz_targets/fuzz_target_u16.rs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#![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));
|
||||||
|
}
|
||||||
|
});
|
@ -7,4 +7,13 @@ use ssz::{DecodeError, Decodable, Encodable};
|
|||||||
// Fuzz ssz_decode(u8)
|
// Fuzz ssz_decode(u8)
|
||||||
fuzz_target!(|data: &[u8]| {
|
fuzz_target!(|data: &[u8]| {
|
||||||
let result: Result<(u8, usize), DecodeError> = Decodable::ssz_decode(data, 0);
|
let result: Result<(u8, usize), DecodeError> = Decodable::ssz_decode(data, 0);
|
||||||
|
if data.len() > 0 {
|
||||||
|
// Should have valid result
|
||||||
|
let (number_u8, index) = result.unwrap();
|
||||||
|
assert_eq!(number_u8, data[0]);
|
||||||
|
assert_eq!(index, 2);
|
||||||
|
} else {
|
||||||
|
// Length of 0 should return error
|
||||||
|
assert_eq!(result, Err(DecodeError::TooShort));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user