Fix sign extension of i32 addresses in interpreter memory access#8348
Open
sumleo wants to merge 1 commit intoWebAssembly:mainfrom
Open
Fix sign extension of i32 addresses in interpreter memory access#8348sumleo wants to merge 1 commit intoWebAssembly:mainfrom
sumleo wants to merge 1 commit intoWebAssembly:mainfrom
Conversation
kripken
reviewed
Feb 20, 2026
src/wasm-interpreter.h
Outdated
| size_t indexVal = index.getSingleValue().getUnsigned(); | ||
| if (indexVal >= data->values.size()) { | ||
| trap("array oob"); | ||
| } |
Member
There was a problem hiding this comment.
This looks like a correct fix, but the title and description of the PR look unrelated?
kripken
reviewed
Feb 20, 2026
73c73bb to
1aaf4f9
Compare
Contributor
Author
|
Thanks for catching that! The branch previously contained the wrong change (an array bounds check that was already covered by #8351). I've force-pushed with the actual sign extension fix for |
88aba0f to
624d4c7
Compare
ptr.geti32() returns int32_t, which gets sign-extended to int64_t via C++ ternary promotion rules before being stored as uint64_t. For i32 addresses >= 0x80000000, this produces incorrect 64-bit addresses (e.g., 0xFFFFFFFF80000000 instead of 0x80000000), causing spurious out-of-bounds traps. Fix by casting through uint32_t first to zero-extend instead of sign-extend. Update expected test outputs that contained the old sign-extended trap values.
624d4c7 to
c906298
Compare
kripken
reviewed
Feb 24, 2026
| Address memorySizeBytes = memorySize * Memory::kPageSize; | ||
| uint64_t addr = ptr.type == Type::i32 ? ptr.geti32() : ptr.geti64(); | ||
| uint64_t addr = ptr.type == Type::i32 ? (uint64_t)(uint32_t)ptr.geti32() | ||
| : (uint64_t)ptr.geti64(); |
Member
There was a problem hiding this comment.
Can this just be getUnsigned()? That returns uint64_t.
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.
Summary
getFinalAddressandgetFinalAddressWithoutOffsetin the interpreterptr.geti32()returnsint32_t, which gets sign-extended toint64_tvia C++ ternary promotion rules before being stored asuint64_t0x80000000, this produces incorrect 64-bit values (e.g.,0xFFFFFFFF80000000instead of0x80000000), causing spurious out-of-bounds trapsuint32_tfirst to zero-extend instead of sign-extendTest plan
binaryen-unittests)