Skip to content

Commit

Permalink
Add initial naive fuzz testing based on wasm-smith (#405)
Browse files Browse the repository at this point in the history
* remove .idea from .gitignore

Developers should instead ignore .idea files locally.

* initial impl for Wasm parsing, validation and translation fuzz testing

This very simple implementation already found a bug in the wasmi_v1 Wasm -> wasmi bytecode translation procedure.
  • Loading branch information
Robbepop committed Aug 12, 2022
1 parent 3886d91 commit 4d1f2ad
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
**/*.rs.bk
Cargo.lock
spec/target
.idea

**/fuzz/corpus/
**/fuzz/target/
**/fuzz/artifacts/
26 changes: 26 additions & 0 deletions wasmi_v1/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "wasmi-fuzz"
version = "0.0.0"
authors = ["Parity Technologies <admin@parity.io>", "Robin Freyler <robin.freyler@gmail.com>"]
publish = false
edition = "2021"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"
wasm-smith = "0.11"

[dependencies.wasmi]
path = ".."

# Prevent this from interfering with workspaces
[workspace]
members = ["."]

[[bin]]
name = "translate"
path = "fuzz_targets/translate.rs"
test = false
doc = false
9 changes: 9 additions & 0 deletions wasmi_v1/fuzz/fuzz_targets/translate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#![no_main]
use libfuzzer_sys::fuzz_target;
use wasmi::{Engine, Module};

fuzz_target!(|data: wasm_smith::Module| {
let wasm = data.to_bytes();
let engine = Engine::default();
Module::new(&engine, &mut &wasm[..]).unwrap();
});

0 comments on commit 4d1f2ad

Please sign in to comment.