Fix access to VMMemoryDefinition::current_length on big-endian (#3013)
The current_length member is defined as "usize" in Rust code, but generated wasm code refers to it as if it were "u32". While this happens to mostly work on little-endian machines (as long as the length is < 4GB), it will always fail on big-endian machines. Fixed by making current_length "u32" in Rust as well, and ensuring the actual memory size is always less than 4GB.
This commit is contained in:
@@ -703,10 +703,10 @@ impl Instance {
|
||||
|
||||
if src
|
||||
.checked_add(len)
|
||||
.map_or(true, |n| n as usize > src_mem.current_length)
|
||||
.map_or(true, |n| n > src_mem.current_length)
|
||||
|| dst
|
||||
.checked_add(len)
|
||||
.map_or(true, |m| m as usize > dst_mem.current_length)
|
||||
.map_or(true, |m| m > dst_mem.current_length)
|
||||
{
|
||||
return Err(Trap::wasm(ir::TrapCode::HeapOutOfBounds));
|
||||
}
|
||||
@@ -741,7 +741,7 @@ impl Instance {
|
||||
|
||||
if dst
|
||||
.checked_add(len)
|
||||
.map_or(true, |m| m as usize > memory.current_length)
|
||||
.map_or(true, |m| m > memory.current_length)
|
||||
{
|
||||
return Err(Trap::wasm(ir::TrapCode::HeapOutOfBounds));
|
||||
}
|
||||
@@ -825,7 +825,7 @@ impl Instance {
|
||||
.map_or(true, |n| n as usize > data.len())
|
||||
|| dst
|
||||
.checked_add(len)
|
||||
.map_or(true, |m| m as usize > memory.current_length)
|
||||
.map_or(true, |m| m > memory.current_length)
|
||||
{
|
||||
return Err(Trap::wasm(ir::TrapCode::HeapOutOfBounds));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user