From 6668e8f87a3d2cf814c1ddd77a0eb6fec668c3eb Mon Sep 17 00:00:00 2001 From: iximeow Date: Sat, 23 Dec 2023 15:41:09 -0800 Subject: more fuzz targets --- fuzz/fuzz_targets/fresh-decode.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 fuzz/fuzz_targets/fresh-decode.rs (limited to 'fuzz/fuzz_targets/fresh-decode.rs') diff --git a/fuzz/fuzz_targets/fresh-decode.rs b/fuzz/fuzz_targets/fresh-decode.rs new file mode 100644 index 0000000..94664aa --- /dev/null +++ b/fuzz/fuzz_targets/fresh-decode.rs @@ -0,0 +1,28 @@ +//! decoding into a pre-existing instruction should not result in different outcomes compared to +//! decoding into a fresh instruction. if decoding succeeds, both outcomes should be equal. + +#![no_main] +use libfuzzer_sys::fuzz_target; + +use yaxpeax_arch::Decoder; + +fuzz_target!(|data: &[u8]| { + + let decoders = [ + yaxpeax_rx::InstDecoder::v1(), + yaxpeax_rx::InstDecoder::v2(), + yaxpeax_rx::InstDecoder::v3(), + ]; + + let mut reused_inst = yaxpeax_rx::Instruction::default(); + + for decoder in decoders { + let mut words = yaxpeax_arch::U8Reader::new(data); + // test decoding, may be ok or not, but should not panic + if let Ok(()) = decoder.decode_into(&mut reused_inst, &mut words) { + let mut words = yaxpeax_arch::U8Reader::new(data); + let fresh_inst = decoder.decode(&mut words).expect("decoded before, can decode again"); + assert_eq!(reused_inst, fresh_inst); + } + } +}); -- cgit v1.1