MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / execute

Function execute

fuzz/fuzz_targets/oom.rs:49–141  ·  view source on GitHub ↗
(
    module: &[u8],
    _known_valid: KnownValid,
    input: OomInput,
    _u: &mut Unstructured<'_>,
)

Source from the content-addressed store, hash-verified

47}
48
49fn execute(
50 module: &[u8],
51 _known_valid: KnownValid,
52 input: OomInput,
53 _u: &mut Unstructured<'_>,
54) -> Result<()> {
55 if cfg!(not(arc_try_new)) {
56 panic!(
57 "The OOM fuzzer is disabled because `cfg(arc_try_new)` was not enabled. Build with \
58 `RUSTFLAGS=--cfg=arc_try_new` to enable."
59 );
60 }
61
62 let module_bytes = match compile(&input.config, module) {
63 Ok(bytes) => bytes,
64 Err(_) => return Ok(()),
65 };
66
67 let mut oom_config = input.config.to_wasmtime();
68 oom_config.enable_compiler(false);
69 oom_config.concurrency_support(false);
70 oom_config.consume_fuel(true);
71
72 // Prevent real process-level OOM: fuzzer-generated configs can set
73 // `memory_reservation(0)`, forcing `mmap` to commit real pages that bypass
74 // `OomTestAllocator`. Use large virtual reservations instead.
75 oom_config.memory_reservation(1 << 32);
76 oom_config.memory_guard_size(1 << 31);
77
78 let oom_engine = match Engine::new(&oom_config) {
79 Ok(e) => e,
80 Err(_) => return Ok(()),
81 };
82
83 let _ = OomTest::new()
84 .seed(input.seed)
85 .max_iters(OOM_TEST_ITERS)
86 .allow_alloc_after_oom(true)
87 .alloc_succeeds_after_oom(true)
88 .allow_missed_oom_errors(true)
89 .fuzz(|| {
90 let module = unsafe { Module::deserialize(&oom_engine, &module_bytes)? };
91
92 let mut store = Store::try_new(&oom_engine, ())?;
93 store.set_fuel(OOM_TEST_FUEL).unwrap();
94
95 let linker = dummy::dummy_linker(&mut store, &module)?;
96 let instance = linker.instantiate(&mut store, &module)?;
97
98 'export_loop: for export in module.exports() {
99 let extern_ty = export.ty();
100 let Some(func_ty) = extern_ty.func() else {
101 continue;
102 };
103 let func = instance.get_func(&mut store, export.name()).unwrap();
104
105 // Build default params; skip if any param type has no default.
106 let mut params: TryVec<Val> = TryVec::with_capacity(func_ty.params().len())?;

Callers

nothing calls this directly

Calls 15

OkFunction · 0.85
dummy_linkerFunction · 0.85
enable_compilerMethod · 0.80
fuzzMethod · 0.80
allow_alloc_after_oomMethod · 0.80
max_itersMethod · 0.80
seedMethod · 0.80
compileFunction · 0.70
newFunction · 0.50
deserializeFunction · 0.50

Tested by

no test coverage detected