summaryrefslogtreecommitdiff
path: root/fuzz
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2025-04-13 19:34:39 -0700
committeriximeow <me@iximeow.net>2025-04-13 19:34:39 -0700
commit6f10ec12b4c81e4d040b933b1e3ee01da5ac9a0c (patch)
treed7e94de37b909b2a6ca29085d3e3c11902df1c30 /fuzz
parent2a7d0f4dd1b7ec13fa402cf7c18dc9f62e8c4b55 (diff)
fuzz cases: only 64 system registers, display should never panic
Diffstat (limited to 'fuzz')
-rw-r--r--fuzz/.gitignore3
-rw-r--r--fuzz/Cargo.toml30
-rw-r--r--fuzz/fuzz_targets/fresh-decode.rs21
3 files changed, 54 insertions, 0 deletions
diff --git a/fuzz/.gitignore b/fuzz/.gitignore
new file mode 100644
index 0000000..a092511
--- /dev/null
+++ b/fuzz/.gitignore
@@ -0,0 +1,3 @@
+target
+corpus
+artifacts
diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml
new file mode 100644
index 0000000..5804b25
--- /dev/null
+++ b/fuzz/Cargo.toml
@@ -0,0 +1,30 @@
+[package]
+name = "yaxpeax-hexagon-fuzz"
+version = "0.0.0"
+authors = ["iximeow <me@iximeow.net>"]
+publish = false
+edition = "2021"
+
+[package.metadata]
+cargo-fuzz = true
+
+[dependencies]
+libfuzzer-sys = "0.4"
+yaxpeax-hexagon = { path = ".." }
+yaxpeax-arch = "0.3.1"
+
+# Prevent this from interfering with workspaces
+[workspace]
+members = ["."]
+
+[[bin]]
+name = "no-panic"
+path = "fuzz_targets/no-panic.rs"
+test = false
+doc = false
+
+[[bin]]
+name = "fresh-decode"
+path = "fuzz_targets/fresh-decode.rs"
+test = false
+doc = false
diff --git a/fuzz/fuzz_targets/fresh-decode.rs b/fuzz/fuzz_targets/fresh-decode.rs
new file mode 100644
index 0000000..76a402e
--- /dev/null
+++ b/fuzz/fuzz_targets/fresh-decode.rs
@@ -0,0 +1,21 @@
+//! 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 decoder = yaxpeax_hexagon::InstDecoder::default();
+
+ let mut reused_inst = yaxpeax_hexagon::InstructionPacket::default();
+
+ 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);
+ }
+});