85 releases (21 breaking)

new 0.205.0 Apr 18, 2024
0.203.0 Apr 12, 2024
0.202.0 Mar 26, 2024
0.13.1 Nov 29, 2023
0.1.11 Nov 23, 2020

#665 in WebAssembly

Download history 2506/week @ 2023-12-23 3236/week @ 2023-12-30 4730/week @ 2024-01-06 4868/week @ 2024-01-13 5242/week @ 2024-01-20 5803/week @ 2024-01-27 5140/week @ 2024-02-03 5067/week @ 2024-02-10 6019/week @ 2024-02-17 6893/week @ 2024-02-24 7317/week @ 2024-03-02 8458/week @ 2024-03-09 8911/week @ 2024-03-16 6557/week @ 2024-03-23 8235/week @ 2024-03-30 5992/week @ 2024-04-06

30,978 downloads per month
Used in 4 crates

Apache-2.0 WITH LLVM-exception

1MB
24K SLoC

wasm-smith

A WebAssembly test case generator.

Features

  • Always valid: All generated Wasm modules pass validation. wasm-smith gets past your wasm parser and validator, exercising the guts of your Wasm compiler, runtime, or tool.

  • Supports the full WebAssembly language: Doesn't have blind spots or unimplemented instructions.

  • Implements the Arbitrary trait: Easy to use with cargo fuzz and libfuzzer-sys!

  • Deterministic: Given the same input seed, always generates the same output Wasm module, so you can always reproduce test failures.

  • Plays nice with mutation-based fuzzers: Small changes to the input tend to produce small changes to the output Wasm module. Larger inputs tend to generate larger Wasm modules.

Usage

With cargo fuzz and libfuzzer-sys

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

$ cargo fuzz add my_wasm_smith_fuzz_target

Next, add wasm-smith to your dependencies:

$ cargo add wasm-smith

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:

// fuzz/fuzz_targets/my_wasm_smith_fuzz_target.rs

#![no_main]

use libfuzzer_sys::fuzz_target;
use wasm_smith::Module;

fuzz_target!(|module: Module| {
    let wasm_bytes = module.to_bytes();

    // Your code here...
});

Finally, start fuzzing:

$ 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:

$ cargo install wasm-tools

Convert some arbitrary input into a valid Wasm module:

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

Finally, run your tool on the generated Wasm module:

$ my-wasm-tool test.wasm

Dependencies

~1.3–2.4MB
~44K SLoC