Skip to content

Commit 48fad3b

Browse files
committed
Add cargo-fuzz related files.
1 parent 440417a commit 48fad3b

File tree

5 files changed

+60
-0
lines changed

5 files changed

+60
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ keywords = ["parser", "WebAssembly", "wasm"]
88
description = """
99
A simple event-driven library for parsing WebAssembly binary files.
1010
"""
11+
exclude = ["fuzz/"]
1112

1213
[dependencies]
1314

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,21 @@ fn main() {
3636
}
3737
}
3838
```
39+
40+
## Fuzzing
41+
42+
To fuzz test wasmparser.rs, switch to a nightly Rust compiler and install [cargo-fuzz]:
43+
44+
```
45+
cargo install cargo-fuzz
46+
```
47+
48+
Then, from the root of the repository, run:
49+
50+
```
51+
cargo fuzz run parse
52+
```
53+
54+
If you want to use files as seeds for the fuzzer, add them to `fuzz/corpus/parse/` and restart cargo-fuzz.
55+
56+
[cargo-fuzz]: https://github.com/rust-fuzz/cargo-fuzz

fuzz/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
target
2+
corpus
3+
artifacts

fuzz/Cargo.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[package]
2+
name = "wasmparser-fuzz"
3+
version = "0.0.1"
4+
authors = ["Yury Delendik <[email protected]>"]
5+
publish = false
6+
7+
[package.metadata]
8+
cargo-fuzz = true
9+
10+
[dependencies.wasmparser]
11+
path = ".."
12+
13+
[dependencies.libfuzzer-sys]
14+
git = "https://github.com/rust-fuzz/libfuzzer-sys.git"
15+
16+
# Prevent this from interfering with workspaces
17+
[workspace]
18+
members = ["."]
19+
20+
[[bin]]
21+
name = "parse"
22+
path = "fuzz_targets/parse.rs"

fuzz/fuzz_targets/parse.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![no_main]
2+
3+
#[macro_use]
4+
extern crate libfuzzer_sys;
5+
extern crate wasmparser;
6+
7+
fuzz_target!(|data: &[u8]| {
8+
let mut parser = wasmparser::Parser::new(data);
9+
loop {
10+
match *parser.read() {
11+
wasmparser::ParserState::Error(..) |
12+
wasmparser::ParserState::EndWasm => break,
13+
_ => (),
14+
}
15+
}
16+
});

0 commit comments

Comments
 (0)