transcode: normalize FACT transcoder i32 arguments to u32 (review) - #303
Merged
Conversation
Core wasm delivers i32 params to a JS import as signed numbers. Every other i32-taking intrinsic normalizes with `>>> 0` (intrinsics/mod.ts resource trampolines, boundary.ts realloc results); the twelve FACT transcoders did not. FACT's generated adapter validates `src_ptr + len <= memory.size` UNSIGNED (wasmtime-environ `validate_guest_pointer` extends with I64ExtendI32U), so a pointer in [2^31, 2^32) is legal once a wasm32 memory grows past 2 GiB — and arrived here negative: `Uint8Array.slice(negative)` read from the END of the buffer (silently wrong bytes), `dst[neg + i] =` was a silent no-op, `dst.set(copy, neg)` threw a non-Trap RangeError. wasmtime copies the right bytes with no trap. Normalized once, in `createTranscoder`, so the twelve arms stay untouched. Regression: transcode_high_ptr_test.ts (allocates a ~2.4 GiB memory; `ignore`d with a reason where the host cannot).
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.
Adversarial correctness review of
main@ 396a216, CABI track — the one divergence found in an otherwise faithful port.The twelve FACT transcoders received
srcPtr/dstPtr/lengths as signed i32 (no>>> 0, unlike every other i32-taking intrinsic). FACT validates guest pointers UNSIGNED (wasmtime-environvalidate_guest_pointerextends withI64ExtendI32U), so a pointer in [2^31, 2^32) is legal once a wasm32 memory exceeds 2 GiB — and arrived negative:slice(negative)read from the end of the buffer (silent wrong bytes), negative-index writes were silent no-ops,set(copy, negative)threw a non-Trap RangeError. wasmtime copies the right bytes.Fix: normalize once in
createTranscoder. Regression:transcode_high_ptr_test.ts(3 tests; allocates a ~2.4 GiB memory,ignored with a reason where the host cannot — it can on the CI runners' class of machine, and did locally).Gates:
just test-runtimegreen;just conformance0 failed; fulljust gatesgreen on the union of the five review PRs.Automerge armed.