From dd8bd5ce0772b08c271205508e48e98ef1c58ea8 Mon Sep 17 00:00:00 2001 From: iximeow Date: Mon, 24 Jun 2024 14:06:22 -0700 Subject: justify the current max instruction length this is also checked by a new fuzz target --- .../instruction_text_buffer_size_ok.rs | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 fuzz/fuzz_targets/instruction_text_buffer_size_ok.rs (limited to 'fuzz/fuzz_targets') diff --git a/fuzz/fuzz_targets/instruction_text_buffer_size_ok.rs b/fuzz/fuzz_targets/instruction_text_buffer_size_ok.rs new file mode 100644 index 0000000..2c88424 --- /dev/null +++ b/fuzz/fuzz_targets/instruction_text_buffer_size_ok.rs @@ -0,0 +1,51 @@ +#![no_main] +#[macro_use] extern crate libfuzzer_sys; +extern crate yaxpeax_x86; +extern crate yaxpeax_arch; + +use std::fmt::Write; + +fuzz_target!(|data: &[u8]| { + let x86_64_decoder = yaxpeax_x86::long_mode::InstDecoder::default(); + let x86_32_decoder = yaxpeax_x86::protected_mode::InstDecoder::default(); + let x86_16_decoder = yaxpeax_x86::real_mode::InstDecoder::default(); + + if let Ok(inst) = x86_64_decoder.decode_slice(data) { + use yaxpeax_x86::long_mode::DisplayStyle; + + let mut s = String::new(); + write!(s, "{}", inst.display_with(DisplayStyle::Intel)).expect("can write"); + // MAX_INSTRUCTION_LEN is not a public crate item yet... + assert!(s.len() < 512); + s.clear(); + write!(s, "{}", inst.display_with(DisplayStyle::C)).expect("can write"); + // MAX_INSTRUCTION_LEN is not a public crate item yet... + assert!(s.len() < 512); + }; + + if let Ok(inst) = x86_32_decoder.decode_slice(data) { + use yaxpeax_x86::protected_mode::DisplayStyle; + + let mut s = String::new(); + write!(s, "{}", inst.display_with(DisplayStyle::Intel)).expect("can write"); + // MAX_INSTRUCTION_LEN is not a public crate item yet... + assert!(s.len() < 512); + s.clear(); + write!(s, "{}", inst.display_with(DisplayStyle::C)).expect("can write"); + // MAX_INSTRUCTION_LEN is not a public crate item yet... + assert!(s.len() < 512); + }; + + if let Ok(inst) = x86_16_decoder.decode_slice(data) { + use yaxpeax_x86::real_mode::DisplayStyle; + + let mut s = String::new(); + write!(s, "{}", inst.display_with(DisplayStyle::Intel)).expect("can write"); + // MAX_INSTRUCTION_LEN is not a public crate item yet... + assert!(s.len() < 512); + s.clear(); + write!(s, "{}", inst.display_with(DisplayStyle::C)).expect("can write"); + // MAX_INSTRUCTION_LEN is not a public crate item yet... + assert!(s.len() < 512); + }; +}); -- cgit v1.1