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

Function check_memory_accesses

crates/fuzzing/src/oracles/memory.rs:8–241  ·  view source on GitHub ↗

Oracle to perform the described memory accesses and check that they are all in- or out-of-bounds as expected

(input: MemoryAccesses)

Source from the content-addressed store, hash-verified

6/// Oracle to perform the described memory accesses and check that they are all
7/// in- or out-of-bounds as expected
8pub fn check_memory_accesses(input: MemoryAccesses) {
9 crate::init_fuzzing();
10 log::info!("Testing memory accesses: {input:#x?}");
11
12 let offset = input.offset;
13 let growth = input.growth;
14 let wasm = build_wasm(&input.image, offset);
15 crate::oracles::log_wasm(&wasm);
16 let offset = u64::from(offset);
17
18 let mut config = input.config.to_wasmtime();
19
20 // Force-enable proposals if the heap image needs them.
21 if input.image.memory64 {
22 config.wasm_memory64(true);
23 }
24 if input.image.page_size_log2.is_some() {
25 config.wasm_custom_page_sizes(true);
26 }
27
28 let engine = Engine::new(&config).unwrap();
29 let module = match Module::new(&engine, &wasm) {
30 Ok(m) => m,
31 Err(e) => {
32 let e = format!("{e:?}");
33 log::info!("Failed to create `Module`: {e}");
34 assert!(
35 e.contains("bytes which exceeds the configured maximum of")
36 || e.contains("exceeds the limit of"),
37 "bad module compilation error: {e:?}",
38 );
39 return;
40 }
41 };
42
43 let limits = super::StoreLimits::new();
44 let mut store = Store::new(&engine, limits);
45 input.config.configure_store(&mut store);
46
47 // If we are using fuel, make sure we add enough that we won't ever run out.
48 if input.config.wasmtime.consume_fuel {
49 store.set_fuel(u64::MAX).unwrap();
50 }
51
52 let instance = match Instance::new(&mut store, &module, &[]) {
53 Ok(x) => x,
54 Err(e) => {
55 log::info!("Failed to instantiate: {e:?}");
56 assert!(
57 format!("{e:?}").contains("Cannot allocate memory"),
58 "bad error: {e:?}",
59 );
60 return;
61 }
62 };
63
64 let memory = instance.get_memory(&mut store, "memory").unwrap();
65 let load8 = instance

Callers 2

smoke_test_memory_accessFunction · 0.85
memory_accessesFunction · 0.85

Calls 15

init_fuzzingFunction · 0.85
log_wasmFunction · 0.85
fromFunction · 0.85
configure_storeMethod · 0.80
checked_subMethod · 0.80
build_wasmFunction · 0.70
newFunction · 0.50
to_wasmtimeMethod · 0.45
wasm_memory64Method · 0.45
is_someMethod · 0.45
unwrapMethod · 0.45

Tested by 1

smoke_test_memory_accessFunction · 0.68