Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,19 @@ jobs:
cargo build --verbose
- name: Run tests
run: cargo test --verbose

fuzz:
name: Fuzzing
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build
run: |
rustup update nightly
cargo install cargo-fuzz
cargo +nightly fuzz build

- name: Fuzz
run: |
cargo +nightly fuzz run module -- -max_total_time=180
cargo +nightly fuzz run component -- -max_total_time=180
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ wasmparser = "0.215.0"
tempfile = "3.10.1"
serde_json = "1.0.121"
log = "0.4.22"
wasm-smith = "0.215.0"

[dev-dependencies]
wasmprinter = "0.215.0"
Expand Down
4 changes: 4 additions & 0 deletions fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target
corpus
artifacts
coverage
31 changes: 31 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[package]
name = "orca-fuzz"
version = "0.0.0"
publish = false
edition = "2021"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"
wasm-smith = "0.215.0"
wasmprinter = "0.215.0"


[dependencies.orca]
path = ".."

[[bin]]
name = "component"
path = "fuzz_targets/component.rs"
test = false
doc = false
bench = false

[[bin]]
name = "module"
path = "fuzz_targets/module.rs"
test = false
doc = false
bench = false
23 changes: 23 additions & 0 deletions fuzz/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
How to run the fuzzer:

```
rustup update nightly
```

```
cargo install cargo-fuzz
```

```
cargo +nightly fuzz build
```

To run roundtrips for modules.
```
cargo +nightly fuzz run orca
```

To run roundtrips for components.
```
cargo +nightly fuzz run component
```
28 changes: 28 additions & 0 deletions fuzz/fuzz_targets/component.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// fuzzing roundtrips for component
#![no_main]

use libfuzzer_sys::fuzz_target;
use orca;
use wasm_smith::Component;

fuzz_target!(|comp: Component| {
let wasm_bytes = comp.to_bytes();
// write to file
use std::fs::File;
use std::io::prelude::*;
let mut file = File::create("temp.wat").unwrap();

let original = wasmprinter::print_bytes(wasm_bytes.clone())
.expect("couldn't convert original Wasm to wat");
file.write_all(&original.clone().into_bytes()).unwrap();
// println!("original:\n {:?}", original);

let mut wasm_comp = orca::Component::parse(&wasm_bytes, false).unwrap();
let roundtrip_bytes = wasm_comp.encode();

let roundtrip = wasmprinter::print_bytes(roundtrip_bytes.clone())
.expect("couldn't convert roundtrip Wasm to wat");
// println!("roundtrip:\n {:?}", roundtrip);

assert_eq!(original, roundtrip);
});
29 changes: 29 additions & 0 deletions fuzz/fuzz_targets/module.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// fuzzing roundtrips for modules

#![no_main]

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

fuzz_target!(|module: Module| {
let wasm_bytes = module.to_bytes();
// write to file
use std::fs::File;
use std::io::prelude::*;
let mut file = File::create("temp.wat").unwrap();

let original = wasmprinter::print_bytes(wasm_bytes.clone())
.expect("couldn't convert original Wasm to wat");
file.write_all(&original.clone().into_bytes()).unwrap();
// println!("original:\n {:?}", original);

let mut wasm_module = orca::Module::parse(&wasm_bytes, false).unwrap();
let roundtrip_bytes = wasm_module.encode();

let roundtrip = wasmprinter::print_bytes(roundtrip_bytes.clone())
.expect("couldn't convert roundtrip Wasm to wat");
// println!("roundtrip:\n {:?}", roundtrip);

assert_eq!(original, roundtrip);
});