wasm-smith

A WebAssembly test case generator.

Rust

Features

Usage

With cargo fuzz and libfuzzer-sys

First, use cargo fuzz to define a new fuzz target:

shell $ cargo fuzz add my_wasm_smith_fuzz_target

Next, add wasm-smith to your dependencies:

```toml

fuzz/Cargo.toml

[dependencies] wasm-smith = "0.4.0" ```

Then, define your fuzz target so that it takes arbitrary wasm_smith::Modules as an argument, convert the module into serialized Wasm bytes via the to_bytes method, and then feed it into your system:

```rust // fuzz/fuzztargets/mywasmsmithfuzz_target.rs

![no_main]

use libfuzzersys::fuzztarget; use wasm_smith::Module;

fuzztarget!(|module: Module| { let wasmbytes = module.to_bytes();

// Your code here...

}); ```

Finally, start fuzzing:

shell $ cargo fuzz run my_wasm_smith_fuzz_target

Note: Also check out the validate fuzz target defined in this repository. Using the wasmparser crate, it checks that every module generated by wasm-smith validates successfully.

As a Command Line Tool

Install the CLI tool via cargo:

shell $ cargo install --git https://github.com/bytecodealliance/wasm-tools

Convert some arbitrary input into a valid Wasm module:

shell $ head -c 100 /dev/urandom | wasm-smith -o test.wasm

Finally, run your tool on the generated Wasm module:

shell $ my-wasm-tool test.wasm