aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mssola@mssola.com>2026-10-19 21:35:22 +0200
committerMiquel Sabaté Solà <mssola@mssola.com>2026-10-19 21:35:22 +0200
commit51f8583447a97fbd913ef961bf85a22a925395cc (patch)
treeadb25827f65e3780c2e673a3f9c2b324e402dc90
parent84be0dea9d3e32785f786fe40af1adbad24ce9e0 (diff)
downloadtools.nes-51f8583447a97fbd913ef961bf85a22a925395cc.tar.gz
tools.nes-51f8583447a97fbd913ef961bf85a22a925395cc.zip
vnf: add fuzzy testing
This takes advantage of the fact that fuzzy testing happens after building all the ROM files. With that, we can use these files so libfuzzer can take them as the corpus. Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
-rw-r--r--lib/vnf/fuzz/.gitignore4
-rw-r--r--lib/vnf/fuzz/Cargo.lock145
-rw-r--r--lib/vnf/fuzz/Cargo.toml24
-rw-r--r--lib/vnf/fuzz/fuzz_targets/fuzz-target-vnf.rs12
-rwxr-xr-xscripts/fuzz.sh9
5 files changed, 194 insertions, 0 deletions
diff --git a/lib/vnf/fuzz/.gitignore b/lib/vnf/fuzz/.gitignore
new file mode 100644
index 0000000..1a45eee
--- /dev/null
+++ b/lib/vnf/fuzz/.gitignore
@@ -0,0 +1,4 @@
+target
+corpus
+artifacts
+coverage
diff --git a/lib/vnf/fuzz/Cargo.lock b/lib/vnf/fuzz/Cargo.lock
new file mode 100644
index 0000000..5d84e99
--- /dev/null
+++ b/lib/vnf/fuzz/Cargo.lock
@@ -0,0 +1,145 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "arbitrary"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3bc62ac97cc33321f50863d514c3bc38a453947a8f9e781137e47c7401020aed"
+
+[[package]]
+name = "cc"
+version = "1.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "877bf67ac8e52449eb2f9e98a344ea163beb70dd1f9eebe3cc5357dcfeaee4df"
+dependencies = [
+ "find-msvc-tools",
+ "jobserver",
+ "libc",
+ "shlex",
+]
+
+[[package]]
+name = "cfg-if"
+version = "1.0.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
+
+[[package]]
+name = "chacha20"
+version = "0.10.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06"
+dependencies = [
+ "cfg-if",
+ "cpufeatures",
+ "rand_core",
+]
+
+[[package]]
+name = "cpufeatures"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "find-msvc-tools"
+version = "0.1.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48"
+
+[[package]]
+name = "getrandom"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099"
+dependencies = [
+ "cfg-if",
+ "libc",
+ "r-efi",
+ "rand_core",
+]
+
+[[package]]
+name = "header"
+version = "0.1.0"
+
+[[package]]
+name = "jobserver"
+version = "0.1.35"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3"
+dependencies = [
+ "getrandom",
+ "libc",
+]
+
+[[package]]
+name = "libc"
+version = "0.2.191"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
+
+[[package]]
+name = "libfuzzer-sys"
+version = "0.4.13"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a9fd2f41a1cba099f79a0b6b6c35656cf7c03351a7bae8ff0f28f25270f929d2"
+dependencies = [
+ "arbitrary",
+ "cc",
+]
+
+[[package]]
+name = "r-efi"
+version = "6.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
+
+[[package]]
+name = "rand"
+version = "0.10.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "65c9fb96cbc91e3478eaae79a69fcd3f1ae4ad052e471fe6732fff548984b4af"
+dependencies = [
+ "chacha20",
+ "getrandom",
+ "rand_core",
+]
+
+[[package]]
+name = "rand_core"
+version = "0.10.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
+
+[[package]]
+name = "shlex"
+version = "2.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
+
+[[package]]
+name = "vnf"
+version = "0.1.0"
+dependencies = [
+ "header",
+ "rand",
+ "xixanta",
+]
+
+[[package]]
+name = "vnf-fuzz"
+version = "0.0.0"
+dependencies = [
+ "libfuzzer-sys",
+ "vnf",
+]
+
+[[package]]
+name = "xixanta"
+version = "0.1.0"
diff --git a/lib/vnf/fuzz/Cargo.toml b/lib/vnf/fuzz/Cargo.toml
new file mode 100644
index 0000000..7b1ec5e
--- /dev/null
+++ b/lib/vnf/fuzz/Cargo.toml
@@ -0,0 +1,24 @@
+[package]
+name = "vnf-fuzz"
+version = "0.0.0"
+publish = false
+edition = "2024"
+
+[workspace]
+members = []
+
+[package.metadata]
+cargo-fuzz = true
+
+[dependencies]
+libfuzzer-sys = "0.4"
+
+[dependencies.vnf]
+path = ".."
+
+[[bin]]
+name = "fuzz-target-vnf"
+path = "fuzz_targets/fuzz-target-vnf.rs"
+test = false
+doc = false
+bench = false
diff --git a/lib/vnf/fuzz/fuzz_targets/fuzz-target-vnf.rs b/lib/vnf/fuzz/fuzz_targets/fuzz-target-vnf.rs
new file mode 100644
index 0000000..2b3b0ed
--- /dev/null
+++ b/lib/vnf/fuzz/fuzz_targets/fuzz-target-vnf.rs
@@ -0,0 +1,12 @@
+#![no_main]
+
+use libfuzzer_sys::fuzz_target;
+
+fuzz_target!(|data: &[u8]| {
+ let policy = vnf::MemoryPolicy::default();
+ let Ok(s) = std::str::from_utf8(data) else {
+ return;
+ };
+ let path = std::path::Path::new(s);
+ let _ = vnf::Machine::from(path, 0x8000, policy);
+});
diff --git a/scripts/fuzz.sh b/scripts/fuzz.sh
index d2fd00a..fb13e49 100755
--- a/scripts/fuzz.sh
+++ b/scripts/fuzz.sh
@@ -10,3 +10,12 @@ popd
pushd lib/header
cargo +nightly fuzz run fuzz-target-header -- -max_total_time=180
popd
+
+# For vnf, we want to give it some ROM files as a corpus so it does a better job
+# at fuzzing, otherwise vnf would just return a super early normal error and
+# quit.
+mkdir -p lib/vnf/fuzz/corpus/fuzz-target-vnf
+cp tests/out/*.nes lib/vnf/fuzz/corpus/fuzz-target-vnf/
+pushd lib/vnf
+cargo +nightly fuzz run fuzz-target-vnf -- -max_total_time=180
+popd