aboutsummaryrefslogtreecommitdiff
path: root/fuzz
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2024-06-24 14:06:22 -0700
committeriximeow <me@iximeow.net>2024-06-24 14:27:25 -0700
commitdd8bd5ce0772b08c271205508e48e98ef1c58ea8 (patch)
tree946630c89a554843dd33a9988a36bb43db48d539 /fuzz
parentddde47c4c8c2058379b448894bebb3e099ea0585 (diff)
justify the current max instruction length
this is also checked by a new fuzz target
Diffstat (limited to 'fuzz')
-rw-r--r--fuzz/Cargo.toml6
-rw-r--r--fuzz/fuzz_targets/instruction_text_buffer_size_ok.rs51
2 files changed, 57 insertions, 0 deletions
diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml
index 2203dc3..a1f871e 100644
--- a/fuzz/Cargo.toml
+++ b/fuzz/Cargo.toml
@@ -36,6 +36,12 @@ test = false
doc = false
[[bin]]
+name = "instruction_text_buffer_size_ok"
+path = "fuzz_targets/instruction_text_buffer_size_ok.rs"
+test = false
+doc = false
+
+[[bin]]
name = "display_c_does_not_panic"
path = "fuzz_targets/display_c_does_not_panic.rs"
test = false
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);
+ };
+});