fix: preserve TypedArray view byteOffset/byteLength in randomFill#955
Merged
fix: preserve TypedArray view byteOffset/byteLength in randomFill#955
Conversation
randomFillSync, randomFill, and getRandomValues corrupted the entire underlying ArrayBuffer when called with a TypedArray view (byteOffset > 0). Capture the view's byteOffset and byteLength before abvToArrayBuffer() strips them, then pass the correct offset and size to native. Also fix the C++ bounds check (offset + size <= buffer length) and update a stale comment in DiffieHellman.cpp. Closes #953
…ecks Add assertions that the target view regions were actually filled with random data (not silently no-op'd), and add an async randomFill test for the view-over-larger-buffer scenario.
Contributor
🤖 End-to-End Test Results - AndroidStatus: ✅ Passed 📸 Final Test ScreenshotScreenshot automatically captured from End-to-End tests and will expire in 30 days This comment is automatically updated on each test run. |
Contributor
🤖 End-to-End Test Results - iOSStatus: ✅ Passed 📸 Final Test ScreenshotScreenshot automatically captured from End-to-End tests and will expire in 30 days This comment is automatically updated on each test run. |
boorad
added a commit
that referenced
this pull request
Feb 24, 2026
New pages: PQC (ML-DSA/ML-KEM), Argon2, KMAC, Certificate (SPKAC), and Utilities (one-shot hash, timingSafeEqual, primes, introspection). Updated 8 existing pages with missing API sections: SubtleCrypto (deriveBits, deriveKey, wrapKey/unwrapKey, encapsulation), Keys (KeyObject.from, equals, toCryptoKey), Signing (standalone sign/verify), DiffieHellman (diffieHellman function), Ed25519 (Ed448/X448), Hash (crypto.hash one-shot, SHA3), ECDH (convertKey), and reorganized the API index into Core/Key Exchange/Key Derivation/Advanced sections. Annotated 7 pages with behavioral notes from recent fix PRs (#929, #930, #932, #933, #939, #948, #949, #951, #954, #955): cipher single-use warning, generateKeys preservation, PBKDF2 validation, OAEP hash default, randomFill view correctness, RSA-* aliases, and flexible curve names. Added llms.txt index route and fixed llms-full.txt JSX stripping in source.ts to produce clean LLM-friendly output.
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
Fixes #953 —
randomFillSync,randomFill, andgetRandomValuescorrupted memory outside the intended region when called with a TypedArray view over a larger ArrayBuffer.Changes
src/random.ts: ExtractbyteOffsetandbyteLengthfrom TypedArray views and passviewOffset + offsetto the native layer, so random bytes target the correct region of the underlying ArrayBuffercpp/random/HybridRandom.cpp: FixcheckOffsetto not compare offset against size (wrong param), and add proper bounds check (offset + size > buffer->size()) before callingRAND_bytescpp/dh/HybridDiffieHellman.cpp: Minor comment correction (get0→get1)getRandomValues,randomFillSync(with and without offset/size), and asyncrandomFillTesting
Run the
randomtest suite in the example app. The new tests verify:Fixes #953