Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Adjust fuel consumption of maps (#12875)

Alex Crichton5d52f56cf589
diff --git a/crates/wasmtime/src/runtime/component/func/typed.rs b/crates/wasmtime/src/runtime/component/func/typed.rs
index 360d82a975..f1fb7de6a9 100644
--- a/crates/wasmtime/src/runtime/component/func/typed.rs
+++ b/crates/wasmtime/src/runtime/component/func/typed.rs
@@ -2315,7 +2315,7 @@ where
.checked_mul(usize::try_from(map.entry_abi.size32)?)
.and_then(|total| ptr.checked_add(total))
{
- Some(n) if n <= cx.memory().len() => cx.consume_fuel(n - ptr)?,
+ Some(n) if n <= cx.memory().len() => cx.consume_fuel_array(len, size_of::<(K, V)>())?,
_ => bail!("map pointer/length out of bounds of memory"),
}
if ptr % (map.entry_abi.align32 as usize) != 0 {
diff --git a/crates/wasmtime/src/runtime/component/values.rs b/crates/wasmtime/src/runtime/component/values.rs
index af5d0b1a2f..5551c4bc45 100644
--- a/crates/wasmtime/src/runtime/component/values.rs
+++ b/crates/wasmtime/src/runtime/component/values.rs
@@ -1001,7 +1001,7 @@ fn load_map(cx: &mut LiftContext<'_>, ty: TypeMapIndex, ptr: usize, len: usize)
.checked_mul(tuple_size)
.and_then(|len| ptr.checked_add(len))
{
- Some(n) if n <= cx.memory().len() => cx.consume_fuel(n - ptr)?,
+ Some(n) if n <= cx.memory().len() => cx.consume_fuel_array(len, size_of::<(Val, Val)>())?,
_ => bail!("map pointer/length out of bounds of memory"),
}
if ptr % usize::try_from(tuple_alignment)? != 0 {