Skip to content

Commit 5d52f56

Browse files
authored
Adjust fuel consumption of maps (#12875)
Consume fuel based on the host's representation of memory rather than the guest's. This matches what arrays do, for example.
1 parent 63a6358 commit 5d52f56

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

crates/wasmtime/src/runtime/component/func/typed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2315,7 +2315,7 @@ where
23152315
.checked_mul(usize::try_from(map.entry_abi.size32)?)
23162316
.and_then(|total| ptr.checked_add(total))
23172317
{
2318-
Some(n) if n <= cx.memory().len() => cx.consume_fuel(n - ptr)?,
2318+
Some(n) if n <= cx.memory().len() => cx.consume_fuel_array(len, size_of::<(K, V)>())?,
23192319
_ => bail!("map pointer/length out of bounds of memory"),
23202320
}
23212321
if ptr % (map.entry_abi.align32 as usize) != 0 {

crates/wasmtime/src/runtime/component/values.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ fn load_map(cx: &mut LiftContext<'_>, ty: TypeMapIndex, ptr: usize, len: usize)
10011001
.checked_mul(tuple_size)
10021002
.and_then(|len| ptr.checked_add(len))
10031003
{
1004-
Some(n) if n <= cx.memory().len() => cx.consume_fuel(n - ptr)?,
1004+
Some(n) if n <= cx.memory().len() => cx.consume_fuel_array(len, size_of::<(Val, Val)>())?,
10051005
_ => bail!("map pointer/length out of bounds of memory"),
10061006
}
10071007
if ptr % usize::try_from(tuple_alignment)? != 0 {

0 commit comments

Comments
 (0)