/src/wasmer/fuzz/fuzz_targets/universal_singlepass.rs
Line | Count | Source (jump to first uncovered line) |
1 | | #![no_main] |
2 | | |
3 | | use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target}; |
4 | | use wasm_smith::{Config, ConfiguredModule}; |
5 | | use wasmer::{imports, Instance, Module, Store}; |
6 | | use wasmer_compiler_singlepass::Singlepass; |
7 | | |
8 | 0 | #[derive(Arbitrary, Debug, Default, Copy, Clone)] <universal_singlepass::NoImportsConfig as arbitrary::Arbitrary>::arbitrary::{closure#1} Line | Count | Source | 8 | 12.6k | #[derive(Arbitrary, Debug, Default, Copy, Clone)] |
Unexecuted instantiation: <universal_singlepass::NoImportsConfig as arbitrary::Arbitrary>::arbitrary::{closure#0} Unexecuted instantiation: <universal_singlepass::NoImportsConfig as arbitrary::Arbitrary>::arbitrary::{closure#2} Unexecuted instantiation: <universal_singlepass::NoImportsConfig as arbitrary::Arbitrary>::arbitrary_take_rest::{closure#1} Unexecuted instantiation: <universal_singlepass::NoImportsConfig as arbitrary::Arbitrary>::arbitrary_take_rest::{closure#0} Unexecuted instantiation: <universal_singlepass::NoImportsConfig as arbitrary::Arbitrary>::arbitrary_take_rest::{closure#2} Unexecuted instantiation: <universal_singlepass::NoImportsConfig as arbitrary::Arbitrary>::size_hint::{closure#0} |
9 | | struct NoImportsConfig; |
10 | | impl Config for NoImportsConfig { |
11 | 12.6k | fn max_imports(&self) -> usize { |
12 | 12.6k | 0 |
13 | 12.6k | } |
14 | 4.39k | fn max_memory_pages(&self) -> u32 { |
15 | 4.39k | // https://github.com/wasmerio/wasmer/issues/2187 |
16 | 4.39k | 65535 |
17 | 4.39k | } |
18 | 12.6k | fn allow_start_export(&self) -> bool { |
19 | 12.6k | false |
20 | 12.6k | } |
21 | | } |
22 | 12.6k | #[derive(Arbitrary)] Unexecuted instantiation: <universal_singlepass::WasmSmithModule as arbitrary::Arbitrary>::arbitrary::{closure#0} Unexecuted instantiation: <universal_singlepass::WasmSmithModule as arbitrary::Arbitrary>::arbitrary::{closure#1} Unexecuted instantiation: <universal_singlepass::WasmSmithModule as arbitrary::Arbitrary>::arbitrary::{closure#2} Unexecuted instantiation: <universal_singlepass::WasmSmithModule as arbitrary::Arbitrary>::arbitrary_take_rest::{closure#0} <universal_singlepass::WasmSmithModule as arbitrary::Arbitrary>::arbitrary_take_rest::{closure#1} Line | Count | Source | 22 | 12.6k | #[derive(Arbitrary)] |
Unexecuted instantiation: <universal_singlepass::WasmSmithModule as arbitrary::Arbitrary>::arbitrary_take_rest::{closure#2} <universal_singlepass::WasmSmithModule as arbitrary::Arbitrary>::size_hint::{closure#0} Line | Count | Source | 22 | 12.6k | #[derive(Arbitrary)] |
|
23 | | struct WasmSmithModule(ConfiguredModule<NoImportsConfig>); |
24 | | impl std::fmt::Debug for WasmSmithModule { |
25 | 0 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
26 | 0 | f.write_str(&wasmprinter::print_bytes(self.0.to_bytes()).unwrap()) |
27 | 0 | } |
28 | | } |
29 | | |
30 | | fuzz_target!(|module: WasmSmithModule| { |
31 | | let wasm_bytes = module.0.to_bytes(); |
32 | | |
33 | | if let Ok(path) = std::env::var("DUMP_TESTCASE") { |
34 | | use std::fs::File; |
35 | | use std::io::Write; |
36 | | let mut file = File::create(path).unwrap(); |
37 | | file.write_all(&wasm_bytes).unwrap(); |
38 | | return; |
39 | | } |
40 | | |
41 | | let compiler = Singlepass::default(); |
42 | | let mut store = Store::new(compiler); |
43 | | let module = Module::new(&store, &wasm_bytes); |
44 | | let module = match module { |
45 | | Ok(m) => m, |
46 | | Err(e) => { |
47 | | let error_message = format!("{}", e); |
48 | | if error_message.contains("Validation error: invalid result arity: func type returns multiple values") || error_message.contains("Validation error: blocks, loops, and ifs may only produce a resulttype when multi-value is not enabled") || error_message.contains("multi-value returns not yet implemented") { |
49 | | return; |
50 | | } |
51 | | panic!("{}", e); |
52 | | } |
53 | | }; |
54 | | match Instance::new(&mut store, &module, &imports! {}) { |
55 | | Ok(_) => {} |
56 | | Err(e) => { |
57 | | let error_message = format!("{}", e); |
58 | | if error_message.starts_with("RuntimeError: ") |
59 | | && error_message.contains("out of bounds") |
60 | | { |
61 | | return; |
62 | | } |
63 | | panic!("{}", e); |
64 | | } |
65 | | } |
66 | | }); |