diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 767300736a..1dd398f965 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -71,7 +71,7 @@ jobs: - uses: ./.github/actions/install-rust with: toolchain: nightly - - run: cargo install cargo-fuzz --vers "^0.6" + - run: cargo install cargo-fuzz --vers "^0.7" - run: cargo fetch working-directory: ./fuzz - run: cargo fuzz build --release --debug-assertions @@ -512,4 +512,3 @@ jobs: files: "dist/*" name: ${{ steps.tagname.outputs.val }} token: ${{ secrets.GITHUB_TOKEN }} - diff --git a/Cargo.lock b/Cargo.lock index 1f24462c3b..f829cc5bff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,6 +30,15 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64cf76cb6e2222ed0ea86b2b0ee2f71c96ec6edd5af42e84d59160e91b836ec4" +[[package]] +name = "arbitrary" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b93b22576af8f14bb2bad6a5dc09c4f80539a801f7ea340c798e222f2ce49859" +dependencies = [ + "derive_arbitrary", +] + [[package]] name = "arrayref" version = "0.3.5" @@ -159,8 +168,8 @@ dependencies = [ "lazycell", "log", "peeking_take_while", - "proc-macro2", - "quote", + "proc-macro2 1.0.7", + "quote 1.0.2", "regex", "rustc-hash", "shlex", @@ -491,8 +500,8 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd8ce37ad4184ab2ce004c33bf6379185d3b1c95801cab51026bd271bf68eedc" dependencies = [ - "quote", - "syn", + "quote 1.0.2", + "syn 1.0.13", ] [[package]] @@ -504,6 +513,17 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "derive_arbitrary" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b979a9f98d526ac07489ae2879e04d948ceeb195d777742997a30c3d1ab1aad6" +dependencies = [ + "proc-macro2 0.4.30", + "syn 0.14.9", + "synstructure 0.9.0", +] + [[package]] name = "digest" version = "0.8.1" @@ -545,9 +565,9 @@ dependencies = [ "byteorder", "lazy_static", "owning_ref", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.7", + "quote 1.0.2", + "syn 1.0.13", ] [[package]] @@ -645,10 +665,10 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bc225b78e0391e4b8683440bf2e63c2deeeb2ce5189eab46e2b68c6d3725d08" dependencies = [ - "proc-macro2", - "quote", - "syn", - "synstructure", + "proc-macro2 1.0.7", + "quote 1.0.2", + "syn 1.0.13", + "synstructure 0.12.3", ] [[package]] @@ -723,9 +743,9 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a36606a68532b5640dc86bb1f33c64b45c4682aad4c50f3937b317ea387f3d6" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.7", + "quote 1.0.2", + "syn 1.0.13", ] [[package]] @@ -817,9 +837,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b714fc08d0961716390977cdff1536234415ac37b509e34e5a983def8340fb75" dependencies = [ "proc-macro-hack", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.7", + "quote 1.0.2", + "syn 1.0.13", "unindent", ] @@ -840,9 +860,9 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a8e30575afe28eea36a9a39136b70b2fb6b0dd0a212a5bd1f30a498395c0274" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.7", + "quote 1.0.2", + "syn 1.0.13", ] [[package]] @@ -895,10 +915,11 @@ checksum = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" [[package]] name = "libfuzzer-sys" -version = "0.1.0" -source = "git+https://github.com/rust-fuzz/libfuzzer-sys.git#0c4507533a79e85e1984f59765bdd35fbdaa7f1b" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94f9e4f036a9cb9f43c637990c03fe045425a33c1c44abf9bc6f555671be5969" dependencies = [ - "arbitrary", + "arbitrary 0.3.2", "cc", ] @@ -1122,9 +1143,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4214c9e912ef61bf42b81ba9a47e8aad1b2ffaf739ab162bf96d1e011f54e6c5" dependencies = [ "proc-macro-hack", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.7", + "quote 1.0.2", + "syn 1.0.13", ] [[package]] @@ -1163,10 +1184,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53c98547ceaea14eeb26fcadf51dc70d01a2479a7839170eae133721105e4428" dependencies = [ "proc-macro-error-attr", - "proc-macro2", - "quote", + "proc-macro2 1.0.7", + "quote 1.0.2", "rustversion", - "syn", + "syn 1.0.13", ] [[package]] @@ -1175,10 +1196,10 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2bf5d493cf5d3e296beccfd61794e445e830dfc8070a9c248ad3ee071392c6c" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.7", + "quote 1.0.2", "rustversion", - "syn", + "syn 1.0.13", "syn-mid", ] @@ -1188,9 +1209,18 @@ version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ecd45702f76d6d3c75a80564378ae228a85f0b59d2f3ed43c91b4a69eb2ebfc5" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.7", + "quote 1.0.2", + "syn 1.0.13", +] + +[[package]] +name = "proc-macro2" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +dependencies = [ + "unicode-xid 0.1.0", ] [[package]] @@ -1199,7 +1229,7 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0319972dcae462681daf4da1adeeaa066e3ebd29c69be96c6abb1259d2ee2bcc" dependencies = [ - "unicode-xid", + "unicode-xid 0.2.0", ] [[package]] @@ -1229,9 +1259,9 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4882d8237fd8c7373cc25cb802fe0dab9ff70830fd56f47ef6c7f3f287fcc057" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.7", + "quote 1.0.2", + "syn 1.0.13", ] [[package]] @@ -1240,10 +1270,10 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fdf321cfab555f7411298733c86d21e5136f5ded13f5872fabf9de3337beecda" dependencies = [ - "proc-macro2", + "proc-macro2 1.0.7", "pyo3-derive-backend", - "quote", - "syn", + "quote 1.0.2", + "syn 1.0.13", ] [[package]] @@ -1264,13 +1294,22 @@ dependencies = [ "rand_core 0.5.1", ] +[[package]] +name = "quote" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" +dependencies = [ + "proc-macro2 0.4.30", +] + [[package]] name = "quote" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" dependencies = [ - "proc-macro2", + "proc-macro2 1.0.7", ] [[package]] @@ -1495,9 +1534,9 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a0538bd897e17257b0128d2fd95c2ed6df939374073a36166051a79e2eb7986" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.7", + "quote 1.0.2", + "syn 1.0.13", ] [[package]] @@ -1527,9 +1566,9 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8584eea9b9ff42825b46faf46a8c24d2cff13ec152fa2a50df788b87c07ee28" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.7", + "quote 1.0.2", + "syn 1.0.13", ] [[package]] @@ -1562,9 +1601,9 @@ version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.7", + "quote 1.0.2", + "syn 1.0.13", ] [[package]] @@ -1647,9 +1686,20 @@ checksum = "0a97f829a34a0a9d5b353a881025a23b8c9fd09d46be6045df6b22920dbd7a93" dependencies = [ "heck", "proc-macro-error", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.7", + "quote 1.0.2", + "syn 1.0.13", +] + +[[package]] +name = "syn" +version = "0.14.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "unicode-xid 0.1.0", ] [[package]] @@ -1658,9 +1708,9 @@ version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e4ff033220a41d1a57d8125eab57bf5263783dfdcc18688b1dacc6ce9651ef8" dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", + "proc-macro2 1.0.7", + "quote 1.0.2", + "unicode-xid 0.2.0", ] [[package]] @@ -1669,9 +1719,21 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fd3937748a7eccff61ba5b90af1a20dbf610858923a9192ea0ecb0cb77db1d0" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.7", + "quote 1.0.2", + "syn 1.0.13", +] + +[[package]] +name = "synstructure" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85bb9b7550d063ea184027c9b8c20ac167cd36d3e06b3a40bceb9d746dc1a7b7" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "syn 0.14.9", + "unicode-xid 0.1.0", ] [[package]] @@ -1680,10 +1742,10 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" dependencies = [ - "proc-macro2", - "quote", - "syn", - "unicode-xid", + "proc-macro2 1.0.7", + "quote 1.0.2", + "syn 1.0.13", + "unicode-xid 0.2.0", ] [[package]] @@ -1758,9 +1820,9 @@ version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb2e25d25307eb8436894f727aba8f65d07adf02e5b35a13cebed48bd282bfef" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.7", + "quote 1.0.2", + "syn 1.0.13", ] [[package]] @@ -1839,6 +1901,12 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" + [[package]] name = "unicode-xid" version = "0.2.0" @@ -1899,9 +1967,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8757b0da38353d55a9687f4dee68a8f441f980dd36e16ab07d6e6c673f505f76" dependencies = [ "heck", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.7", + "quote 1.0.2", + "syn 1.0.13", ] [[package]] @@ -1935,9 +2003,9 @@ dependencies = [ name = "wasi-common-cbindgen" version = "0.9.0" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.7", + "quote 1.0.2", + "syn 1.0.13", "trybuild", ] @@ -2092,7 +2160,7 @@ dependencies = [ name = "wasmtime-fuzz" version = "0.9.0" dependencies = [ - "arbitrary", + "arbitrary 0.2.0", "env_logger 0.7.1", "libfuzzer-sys", "log", @@ -2106,7 +2174,7 @@ name = "wasmtime-fuzzing" version = "0.9.0" dependencies = [ "anyhow", - "arbitrary", + "arbitrary 0.3.2", "binaryen", "env_logger 0.7.1", "log", @@ -2213,9 +2281,9 @@ dependencies = [ name = "wasmtime-rust-macro" version = "0.9.0" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.7", + "quote 1.0.2", + "syn 1.0.13", ] [[package]] @@ -2303,8 +2371,8 @@ name = "wig" version = "0.9.2" dependencies = [ "heck", - "proc-macro2", - "quote", + "proc-macro2 1.0.7", + "quote 1.0.2", "witx", ] diff --git a/crates/fuzzing/Cargo.toml b/crates/fuzzing/Cargo.toml index e6eefeafe7..81b1d471b3 100644 --- a/crates/fuzzing/Cargo.toml +++ b/crates/fuzzing/Cargo.toml @@ -10,7 +10,7 @@ version = "0.9.0" [dependencies] anyhow = "1.0.22" -arbitrary = "0.2.0" +arbitrary = { version = "0.3.2", features = ["derive"] } binaryen = "0.8.2" env_logger = { version = "0.7.1", optional = true } log = "0.4.8" diff --git a/crates/fuzzing/src/generators.rs b/crates/fuzzing/src/generators.rs index 1fb6a29c0f..62ed219aef 100644 --- a/crates/fuzzing/src/generators.rs +++ b/crates/fuzzing/src/generators.rs @@ -31,13 +31,17 @@ impl fmt::Debug for WasmOptTtf { } impl Arbitrary for WasmOptTtf { - fn arbitrary(input: &mut U) -> Result - where - U: Unstructured + ?Sized, - { + fn arbitrary(input: &mut Unstructured) -> arbitrary::Result { let seed: Vec = Arbitrary::arbitrary(input)?; let module = binaryen::tools::translate_to_fuzz_mvp(&seed); let wasm = module.write(); Ok(WasmOptTtf { wasm }) } + + fn arbitrary_take_rest(input: Unstructured) -> arbitrary::Result { + let seed: Vec = Arbitrary::arbitrary_take_rest(input)?; + let module = binaryen::tools::translate_to_fuzz_mvp(&seed); + let wasm = module.write(); + Ok(WasmOptTtf { wasm }) + } } diff --git a/crates/fuzzing/src/generators/api.rs b/crates/fuzzing/src/generators/api.rs index debae64f05..1e59fea39f 100644 --- a/crates/fuzzing/src/generators/api.rs +++ b/crates/fuzzing/src/generators/api.rs @@ -15,8 +15,9 @@ //! [swarm testing]: https://www.cs.utah.edu/~regehr/papers/swarm12.pdf use arbitrary::{Arbitrary, Unstructured}; -use std::collections::HashSet; +use std::collections::BTreeSet; +#[derive(Arbitrary, Debug)] struct Swarm { config_debug_info: bool, module_new: bool, @@ -26,24 +27,8 @@ struct Swarm { call_exported_func: bool, } -impl Arbitrary for Swarm { - fn arbitrary(input: &mut U) -> Result - where - U: Unstructured + ?Sized, - { - Ok(Swarm { - config_debug_info: bool::arbitrary(input)?, - module_new: bool::arbitrary(input)?, - module_drop: bool::arbitrary(input)?, - instance_new: bool::arbitrary(input)?, - instance_drop: bool::arbitrary(input)?, - call_exported_func: bool::arbitrary(input)?, - }) - } -} - /// A call to one of Wasmtime's public APIs. -#[derive(Clone, Debug)] +#[derive(Arbitrary, Clone, Debug)] #[allow(missing_docs)] pub enum ApiCall { ConfigNew, @@ -61,8 +46,8 @@ use ApiCall::*; #[derive(Default)] struct Scope { id_counter: usize, - modules: HashSet, - instances: HashSet, + modules: BTreeSet, + instances: BTreeSet, } impl Scope { @@ -81,10 +66,7 @@ pub struct ApiCalls { } impl Arbitrary for ApiCalls { - fn arbitrary(input: &mut U) -> Result - where - U: Unstructured + ?Sized, - { + fn arbitrary(input: &mut Unstructured) -> arbitrary::Result { let swarm = Swarm::arbitrary(input)?; let mut calls = vec![]; @@ -94,8 +76,8 @@ impl Arbitrary for ApiCalls { let mut scope = Scope::default(); - for _ in 0..input.container_size()? { - let mut choices: Vec Result> = vec![]; + for _ in 0..input.arbitrary_len::()? { + let mut choices: Vec arbitrary::Result> = vec![]; if swarm.module_new { choices.push(|input, scope| { @@ -108,7 +90,7 @@ impl Arbitrary for ApiCalls { if swarm.module_drop && !scope.modules.is_empty() { choices.push(|input, scope| { let modules: Vec<_> = scope.modules.iter().cloned().collect(); - let id = arbitrary_choice(input, &modules)?.cloned().unwrap(); + let id = *input.choose(&modules)?; scope.modules.remove(&id); Ok(ModuleDrop { id }) }); @@ -116,7 +98,7 @@ impl Arbitrary for ApiCalls { if swarm.instance_new && !scope.modules.is_empty() { choices.push(|input, scope| { let modules: Vec<_> = scope.modules.iter().cloned().collect(); - let module = arbitrary_choice(input, &modules)?.cloned().unwrap(); + let module = *input.choose(&modules)?; let id = scope.next_id(); scope.instances.insert(id); Ok(InstanceNew { id, module }) @@ -125,7 +107,7 @@ impl Arbitrary for ApiCalls { if swarm.instance_drop && !scope.instances.is_empty() { choices.push(|input, scope| { let instances: Vec<_> = scope.instances.iter().cloned().collect(); - let id = arbitrary_choice(input, &instances)?.cloned().unwrap(); + let id = *input.choose(&instances)?; scope.instances.remove(&id); Ok(InstanceDrop { id }) }); @@ -133,43 +115,28 @@ impl Arbitrary for ApiCalls { if swarm.call_exported_func && !scope.instances.is_empty() { choices.push(|input, scope| { let instances: Vec<_> = scope.instances.iter().cloned().collect(); - let instance = arbitrary_choice(input, &instances)?.cloned().unwrap(); + let instance = *input.choose(&instances)?; let nth = usize::arbitrary(input)?; Ok(CallExportedFunc { instance, nth }) }); } - if let Some(c) = arbitrary_choice(input, &choices)? { - calls.push(c(input, &mut scope)?); - } else { + if choices.is_empty() { break; } + let c = input.choose(&choices)?; + calls.push(c(input, &mut scope)?); } Ok(ApiCalls { calls }) } } -fn arbitrary_choice<'a, T, U>(input: &mut U, choices: &'a [T]) -> Result, U::Error> -where - U: Unstructured + ?Sized, -{ - if choices.is_empty() { - Ok(None) - } else { - let i = usize::arbitrary(input)? % choices.len(); - Ok(Some(&choices[i])) - } -} - -fn arbitrary_config( - input: &mut U, +fn arbitrary_config( + input: &mut Unstructured, swarm: &Swarm, calls: &mut Vec, -) -> Result<(), U::Error> -where - U: Unstructured + ?Sized, -{ +) -> arbitrary::Result<()> { calls.push(ConfigNew); if swarm.config_debug_info && bool::arbitrary(input)? { diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 996c53b2f3..50dfe42fae 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -15,7 +15,7 @@ log = "0.4.8" wasmtime-fuzzing = { path = "../crates/fuzzing", features = ["env_logger"] } wasmtime-jit = { path = "../crates/jit" } wasmtime = { path = "../crates/api" } -libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git" } +libfuzzer-sys = "0.2.0" [[bin]] name = "compile"