Skip to content

Fix memory64 offset truncation in the interp istream#2799

Open
aizu-m wants to merge 1 commit into
WebAssembly:mainfrom
aizu-m:interp-memory64-offset
Open

Fix memory64 offset truncation in the interp istream#2799
aizu-m wants to merge 1 commit into
WebAssembly:mainfrom
aizu-m:interp-memory64-offset

Conversation

@aizu-m

@aizu-m aizu-m commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Running a memory64 module under wasm-interp, i64.load offset=0x1_0000_0000 from address 0 returned 0 instead of trapping. A large dynamic address (5 GiB) does trap, so the static offset was the suspect.

  1. OnLoadExpr hands the memarg offset over as an Address (u64), but istream_.Emit(opcode, memidx, offset) resolved to Emit(Opcode, u32, u32) and narrowed it to 32 bits.
  2. For an i64-indexed memory a static offset of 2^32 or more is then lost, so an access whose effective address is out of bounds wraps to a small in-range offset and reads or writes a valid location rather than trapping.

Carried the offset as u64 the whole way: added imm_index_offset/imm_index_offset_lane immediates and Emit(Opcode, u32, u64) overloads, widened the four Imm_Index_Offset_* decode groups, the load/store/atomic/simd-lane handlers and the disassembler. 32-bit memories are untouched since the offset always fits u32. Regression test added under test/interp.

The interpreter stored load/store memarg offsets as 32-bit istream immediates, so a memory64 static offset of 2^32 or more was truncated and an access that must trap wrapped into an in-range one. Carry the offset as u64 through emit, decode and the memory handlers.
struct {
u32 memidx;
u64 offset;
u8 lane;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move the lane to first member (or after memIndex) to reduce the structure size increase.
u32+u64+u8 = 24 bytes, while u8+u32+u64 = 16 bytes due to padding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants