wasi-shims: chunk get-random-bytes past the 64KiB getRandomValues quota - #50
Merged
Conversation
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.
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.
Found while scoping the JSPI/blocking-profile work:
get-random-bytes(len > 65536)threwQuotaExceededErrorthrough the provider (unbranded host throw -> trap), because a singlecrypto.getRandomValuescall caps at 64KiB.The WIT allows no shorter return —
random.wit(@since 0.2.0): "Returnlencryptographically-secure random or pseudo-random bytes" — and real callers (Rustgetrandom, 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: exactlen, 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).