Skip to content

Commit 2dbfdab

Browse files
gtreptaScott-Guest
andauthored
Update wasm-smith to 0.218.0 (#1231)
* Update wasm-smith to 0.218.0 * Fix clippy warnings * Make function calls for exec/translate modules more consistent. --------- Co-authored-by: Scott Guest <[email protected]>
1 parent 05c20cf commit 2dbfdab

File tree

7 files changed

+97
-83
lines changed

7 files changed

+97
-83
lines changed

Cargo.lock

Lines changed: 12 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fuzz/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ cargo-fuzz = true
1212

1313
[dependencies]
1414
libfuzzer-sys = "0.4.7"
15-
wasm-smith = "=0.13.1"
16-
arbitrary = { version = "=1.3.2", features = ["derive"] }
1715
wasmi-stack = { package = "wasmi", version = "0.31.2" }
1816
wasmtime = "21.0.1"
1917
wasmi = { workspace = true, features = ["std"] }
18+
wasm-smith = "0.218.0"
19+
arbitrary = "1.3.2"
2020

2121
[[bin]]
2222
name = "translate"

fuzz/fuzz_targets/differential.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ mod utils;
44

55
use libfuzzer_sys::fuzz_target;
66
use std::{collections::hash_map::RandomState, mem};
7-
use utils::{ty_to_val, ExecConfig};
8-
use wasm_smith::ConfiguredModule;
7+
use utils::{arbitrary_exec_module, ty_to_val};
98
use wasmi as wasmi_reg;
109
use wasmi_reg::core::{F32, F64};
1110

@@ -614,11 +613,15 @@ impl FuzzContext {
614613
}
615614
}
616615

617-
fuzz_target!(|cfg_module: ConfiguredModule<ExecConfig>| {
618-
let mut smith_module = cfg_module.module;
616+
fuzz_target!(|data: &[u8]| {
617+
let Ok(mut smith_module) = arbitrary_exec_module(data) else {
618+
return;
619+
};
619620
// Note: We cannot use built-in fuel metering of the different engines since that
620621
// would introduce unwanted non-determinism with respect to fuzz testing.
621-
smith_module.ensure_termination(1_000 /* fuel */);
622+
let Ok(_) = smith_module.ensure_termination(1_000 /* fuel */) else {
623+
return;
624+
};
622625
let wasm = smith_module.to_bytes();
623626
let Some(wasmi_register) = <WasmiRegister as DifferentialTarget>::setup(&wasm[..]) else {
624627
return;

fuzz/fuzz_targets/execute.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,21 @@
33
mod utils;
44

55
use libfuzzer_sys::fuzz_target;
6-
use utils::{ty_to_val, ExecConfig};
7-
use wasm_smith::ConfiguredModule;
6+
use utils::{arbitrary_exec_module, ty_to_val};
87
use wasmi::{Engine, Linker, Module, Store, StoreLimitsBuilder};
98

10-
fuzz_target!(|cfg_module: ConfiguredModule<ExecConfig>| {
11-
let mut smith_module = cfg_module.module;
9+
fuzz_target!(|data: &[u8]| {
10+
let Ok(mut smith_module) = arbitrary_exec_module(data) else {
11+
return;
12+
};
13+
1214
// TODO: We could use Wasmi's built-in fuel metering instead.
1315
// This would improve test coverage and may be more efficient
1416
// given that `wasm-smith`'s fuel metering uses global variables
1517
// to communicate used fuel.
16-
smith_module.ensure_termination(1000 /* fuel */);
18+
let Ok(_) = smith_module.ensure_termination(1000 /* fuel */) else {
19+
return;
20+
};
1721
let wasm = smith_module.to_bytes();
1822
let engine = Engine::default();
1923
let linker = Linker::new(&engine);

fuzz/fuzz_targets/translate.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
#![no_main]
2+
3+
mod utils;
4+
25
use libfuzzer_sys::fuzz_target;
6+
use utils::arbitrary_translate_module;
37
use wasmi::{Engine, Module};
48

5-
fuzz_target!(|data: wasm_smith::Module| {
6-
let wasm = data.to_bytes();
9+
fuzz_target!(|seed: &[u8]| {
10+
let Ok(smith_module) = arbitrary_translate_module(seed) else {
11+
return;
12+
};
13+
let wasm = smith_module.to_bytes();
714
let engine = Engine::default();
815
Module::new(&engine, &wasm[..]).unwrap();
916
});

fuzz/fuzz_targets/translate_metered.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
#![no_main]
2+
3+
mod utils;
4+
25
use libfuzzer_sys::fuzz_target;
6+
use utils::arbitrary_translate_module;
37
use wasmi::{Config, Engine, Module};
48

5-
fuzz_target!(|data: wasm_smith::Module| {
6-
let wasm = data.to_bytes();
9+
fuzz_target!(|seed: &[u8]| {
10+
let Ok(smith_module) = arbitrary_translate_module(seed) else {
11+
return;
12+
};
13+
let wasm = smith_module.to_bytes();
714
let mut config = Config::default();
815
config.consume_fuel(true);
916
let engine = Engine::new(&config);

fuzz/fuzz_targets/utils.rs

Lines changed: 48 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,56 @@
1-
use arbitrary::Arbitrary;
2-
use wasmi::{core::ValType, Val};
1+
#![allow(dead_code)]
32

4-
/// The configuration used to produce Wasmi compatible fuzzing Wasm modules.
5-
#[derive(Debug, Arbitrary)]
6-
pub struct ExecConfig;
3+
use arbitrary::{Arbitrary, Unstructured};
4+
use wasmi::{core::ValType, Val};
75

8-
impl wasm_smith::Config for ExecConfig {
9-
fn export_everything(&self) -> bool {
10-
true
11-
}
12-
fn allow_start_export(&self) -> bool {
13-
false
14-
}
15-
fn reference_types_enabled(&self) -> bool {
16-
false
17-
}
18-
fn max_imports(&self) -> usize {
19-
0
20-
}
21-
fn max_memory_pages(&self, is_64: bool) -> u64 {
22-
match is_64 {
23-
true => {
24-
// Note: wasmi does not support 64-bit memory, yet.
25-
0
26-
}
27-
false => 1_000,
28-
}
29-
}
30-
fn max_data_segments(&self) -> usize {
31-
10_000
32-
}
33-
fn max_element_segments(&self) -> usize {
34-
10_000
35-
}
36-
fn max_exports(&self) -> usize {
37-
10_000
38-
}
39-
fn max_elements(&self) -> usize {
40-
10_000
41-
}
42-
fn min_funcs(&self) -> usize {
43-
1
44-
}
45-
fn max_funcs(&self) -> usize {
46-
10_000
47-
}
48-
fn max_globals(&self) -> usize {
49-
10_000
50-
}
51-
fn max_table_elements(&self) -> u32 {
52-
10_000
53-
}
54-
fn max_values(&self) -> usize {
55-
10_000
56-
}
57-
fn max_instructions(&self) -> usize {
58-
100_000
6+
pub fn exec_config() -> wasm_smith::Config {
7+
wasm_smith::Config {
8+
export_everything: true,
9+
allow_start_export: false,
10+
reference_types_enabled: false,
11+
max_imports: 0,
12+
max_memory32_bytes: (1 << 16) * 1_000,
13+
// Note: wasmi does not support 64-bit memory, yet.
14+
memory64_enabled: false,
15+
max_data_segments: 10_000,
16+
max_element_segments: 10_000,
17+
max_exports: 10_000,
18+
max_elements: 10_000,
19+
min_funcs: 1,
20+
max_funcs: 10_000,
21+
max_globals: 10_000,
22+
max_table_elements: 10_000,
23+
max_values: 10_000,
24+
max_instructions: 100_000,
25+
exceptions_enabled: false,
26+
simd_enabled: false,
27+
threads_enabled: false,
28+
gc_enabled: false,
29+
tail_call_enabled: false,
30+
..Default::default()
5931
}
6032
}
6133

34+
pub fn arbitrary_exec_module(seed: &[u8]) -> arbitrary::Result<wasm_smith::Module> {
35+
let mut unstructured = Unstructured::new(seed);
36+
wasm_smith::Module::new(exec_config(), &mut unstructured)
37+
}
38+
39+
pub fn arbitrary_translate_module(seed: &[u8]) -> arbitrary::Result<wasm_smith::Module> {
40+
let mut unstructured = Unstructured::new(seed);
41+
42+
let config = wasm_smith::Config::arbitrary(&mut unstructured);
43+
44+
config.map(|mut config| {
45+
config.gc_enabled = false;
46+
config.exceptions_enabled = false;
47+
config.simd_enabled = false;
48+
config.threads_enabled = false;
49+
50+
wasm_smith::Module::new(config, &mut unstructured)
51+
})?
52+
}
53+
6254
/// Converts a [`ValType`] into a [`Val`] with default initialization of 1.
6355
///
6456
/// # ToDo

0 commit comments

Comments
 (0)