Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/webgpu/cpp/rnwgpu/ArrayBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ template <> struct JSIConverter<std::shared_ptr<ArrayBuffer>> {
obj.getProperty(runtime, "byteOffset").asNumber());
auto byteLength = static_cast<size_t>(
obj.getProperty(runtime, "byteLength").asNumber());
if (bytesPerElements <= 0 || bytesPerElements > 8) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we guard here, should we also guard that this is an integer value?

throw std::runtime_error(
"ArrayBuffer::fromJSI: BYTES_PER_ELEMENT must be a positive "
"integer between 1 and 8");
}
auto bufferSize = arrayBuffer.size(runtime);
if (byteOffset > bufferSize || byteLength > bufferSize - byteOffset) {
throw std::runtime_error(
"ArrayBuffer::fromJSI: byteOffset + byteLength exceeds buffer "
"size");
}
return std::make_shared<ArrayBuffer>(
arrayBuffer.data(runtime) + byteOffset, byteLength,
static_cast<size_t>(bytesPerElements));
Expand Down