Fix memory64 offset truncation in the interp istream#2799
Open
aizu-m wants to merge 1 commit into
Open
Conversation
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.
zherczeg
reviewed
Jul 22, 2026
| struct { | ||
| u32 memidx; | ||
| u64 offset; | ||
| u8 lane; |
Collaborator
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Running a memory64 module under wasm-interp,
i64.load offset=0x1_0000_0000from address 0 returned 0 instead of trapping. A large dynamic address (5 GiB) does trap, so the static offset was the suspect.Address(u64), butistream_.Emit(opcode, memidx, offset)resolved toEmit(Opcode, u32, u32)and narrowed it to 32 bits.Carried the offset as u64 the whole way: added
imm_index_offset/imm_index_offset_laneimmediates andEmit(Opcode, u32, u64)overloads, widened the fourImm_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.