Security: Potential Memory Safety Issue in ArrayBuffer JSI Converter#360
Open
tomaioo wants to merge 1 commit into
Open
Security: Potential Memory Safety Issue in ArrayBuffer JSI Converter#360tomaioo wants to merge 1 commit into
tomaioo wants to merge 1 commit into
Conversation
In `ArrayBuffer.h`, the `createArrayBufferFromJSI` function creates an shared_ptr<ArrayBuffer> that wraps raw pointers obtained from JSI ArrayBuffer objects. The `byteOffset` and `byteLength` values are cast from `asNumber()` without bounds checking against the actual ArrayBuffer size. A malicious or malformed JSI object could provide values that cause out-of-bounds memory access. Additionally, the `bytesPerElements` value is used without validation, which could lead to incorrect memory calculations. Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
wcandillon
requested changes
May 20, 2026
Owner
wcandillon
left a comment
There was a problem hiding this comment.
Would it be possible to had a test there?
| obj.getProperty(runtime, "byteOffset").asNumber()); | ||
| auto byteLength = static_cast<size_t>( | ||
| obj.getProperty(runtime, "byteLength").asNumber()); | ||
| if (bytesPerElements <= 0 || bytesPerElements > 8) { |
Owner
There was a problem hiding this comment.
if we guard here, should we also guard that this is an integer value?
Author
|
Yes, we should validate that |
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
Security: Potential Memory Safety Issue in ArrayBuffer JSI Converter
Problem
Severity:
High| File:packages/webgpu/cpp/rnwgpu/ArrayBuffer.h:L65In
ArrayBuffer.h, thecreateArrayBufferFromJSIfunction creates an shared_ptr that wraps raw pointers obtained from JSI ArrayBuffer objects. ThebyteOffsetandbyteLengthvalues are cast fromasNumber()without bounds checking against the actual ArrayBuffer size. A malicious or malformed JSI object could provide values that cause out-of-bounds memory access. Additionally, thebytesPerElementsvalue is used without validation, which could lead to incorrect memory calculations.Solution
Add strict bounds checking to ensure
byteOffset + byteLengthdoes not exceed the underlying ArrayBuffer size. ValidatebytesPerElementsis a positive integer within expected ranges. Consider using span or similar bounded view types instead of raw pointers.Changes
packages/webgpu/cpp/rnwgpu/ArrayBuffer.h(modified)