Skip to content

transcode: normalize FACT transcoder i32 arguments to u32 (review) - #303

Merged
lannbot merged 1 commit into
mainfrom
fix/review-transcode-u32
Sep 7, 2026
Merged

transcode: normalize FACT transcoder i32 arguments to u32 (review)#303
lannbot merged 1 commit into
mainfrom
fix/review-transcode-u32

Conversation

@lannbot

@lannbot lannbot commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

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-environ validate_guest_pointer extends with I64ExtendI32U), 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-runtime green; just conformance 0 failed; full just gates green on the union of the five review PRs.

Automerge armed.

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).
@lannbot
lannbot enabled auto-merge September 7, 2026 02:12
@lannbot
lannbot merged commit 35f3910 into main Sep 7, 2026
4 checks passed
@lannbot
lannbot deleted the fix/review-transcode-u32 branch September 7, 2026 02:16
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