Security: Potential Memory Safety Issue in ArrayBuffer JSI Converter#360
Security: Potential Memory Safety Issue in ArrayBuffer JSI Converter#360tomaioo wants to merge 2 commits 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
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) { |
There was a problem hiding this comment.
if we guard here, should we also guard that this is an integer value?
|
Yes, we should validate that |
1 similar comment
|
Yes, we should validate that |
|
Yes, we should validate that |
4 similar comments
|
Yes, we should validate that |
|
Yes, we should validate that |
|
Yes, we should validate that |
|
Yes, we should validate that |
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)