diff --git a/crates/polkavm-common/src/program.rs b/crates/polkavm-common/src/program.rs index 2da09cf1..0647877f 100644 --- a/crates/polkavm-common/src/program.rs +++ b/crates/polkavm-common/src/program.rs @@ -4303,6 +4303,13 @@ impl ProgramBlob { &self.bitmask } + #[cfg(feature = "export-internals-for-testing")] + #[doc(hidden)] + pub fn set_bitmask(&mut self, bitmask: ArcBytes) { + self.bitmask = bitmask; + } + + /// Returns the import offsets and symbols. pub fn imports(&self) -> Imports { Imports { offsets: &self.import_offsets, @@ -4363,7 +4370,7 @@ impl ProgramBlob { } } - /// Visits every instrution in the program. + /// Visits every instruction in the program. #[cfg_attr(not(debug_assertions), inline(always))] pub fn visit(&self, dispatch_table: T, visitor: &mut T::State) where diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock index 9f325bd2..95309bb7 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -104,6 +104,7 @@ dependencies = [ "arbitrary", "libfuzzer-sys", "polkavm", + "polkavm-common", ] [[package]] diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 95cc6900..33898bf4 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -15,6 +15,10 @@ libfuzzer-sys = "0.4" path = "../crates/polkavm" features = ["export-internals-for-testing"] +[dependencies.polkavm-common] +path = "../crates/polkavm-common" +features = ["export-internals-for-testing"] + [[bin]] name = "fuzz_shm_allocator" path = "fuzz_targets/fuzz_shm_allocator.rs" diff --git a/fuzz/fuzz_targets/fuzz_interpreter.rs b/fuzz/fuzz_targets/fuzz_interpreter.rs index bed13ae6..9ec418bb 100644 --- a/fuzz/fuzz_targets/fuzz_interpreter.rs +++ b/fuzz/fuzz_targets/fuzz_interpreter.rs @@ -1,11 +1,11 @@ #![no_main] use libfuzzer_sys::fuzz_target; +use polkavm::Engine; use polkavm::InterruptKind; use polkavm::ModuleConfig; -use polkavm::ProgramBlob; use polkavm::ProgramCounter; -use polkavm::{ArcBytes, Engine}; +use polkavm_common::program::ProgramBlob; fn harness(data: &[u8]) { // configure the polkavm engine @@ -21,15 +21,12 @@ fn harness(data: &[u8]) { module_config.set_step_tracing(true); // create a polkavm program blob (eventually to be filled with the fuzzed data) - let blob = ProgramBlob::default(); + let mut fuzzed_blob = ProgramBlob::default(); let bitmask = vec![0xff; data.len() / 8 + 1]; - let fuzzed_blob = ProgramBlob { - code: data.into(), - bitmask: bitmask.into(), - ..blob - }; + fuzzed_blob.set_code(data.into()); + fuzzed_blob.set_bitmask(bitmask.into()); // create a polkavm module from the engine, module config, and program blob let module = polkavm::Module::from_blob(&engine, &module_config, fuzzed_blob).unwrap();