Skip to content

wasi-shims: chunk get-random-bytes past the 64KiB getRandomValues quota - #50

Merged
lann merged 1 commit into
mainfrom
wasi-shims-random-chunking
Aug 10, 2026
Merged

wasi-shims: chunk get-random-bytes past the 64KiB getRandomValues quota#50
lann merged 1 commit into
mainfrom
wasi-shims-random-chunking

Conversation

@lann

@lann lann commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Found while scoping the JSPI/blocking-profile work: get-random-bytes(len > 65536) threw QuotaExceededError through the provider (unbranded host throw -> trap), because a single crypto.getRandomValues call caps at 64KiB.

The WIT allows no shorter return — random.wit (@since 0.2.0): "Return len cryptographically-secure random or pseudo-random bytes" — and real callers (Rust getrandom, the Go runtime) fill fixed-size buffers trusting the returned length, so a clamp would silently under-randomize key buffers. The fill is chunked instead: exact len, still synchronous per the WIT's must-not-block clause.

Latent in practice (no corpus consumer requests >64KiB per call); pinned by a fail-on-pre-fix test spanning three chunks plus a ragged tail, asserting exact length and per-chunk non-zero windows.

Gates run locally: just test-wasi-shims test-ct-runner (40 + 17 pass).

crypto.getRandomValues rejects a single request over 65536 bytes
(QuotaExceededError, verified on Deno), so get-random-bytes(len > 64KiB)
threw an unbranded host error -> trap. The WIT permits no shorter return
("Return `len` cryptographically-secure random or pseudo-random bytes",
random.wit `@since 0.2.0`) and callers (Rust getrandom, the Go runtime)
fill fixed-size buffers trusting the result length, so the fill is
chunked to exactly len bytes rather than clamped. Latent until now: no
consumer in the corpus requests more than a few hundred bytes per call.

Fail-on-pre-fix pin: random_test.ts spans three chunks plus a ragged
tail and asserts exact length plus per-chunk non-zero windows.
@lann
lann enabled auto-merge August 10, 2026 19:32
@lann
lann merged commit 14e0f11 into main Aug 10, 2026
4 checks passed
@lannbot
lannbot deleted the wasi-shims-random-chunking branch August 23, 2026 16:51
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.

1 participant