Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

Commit 8374411

Browse files
committed
napi: add range check to jsrt version of napi_create_dataview
1 parent 8347baf commit 8374411

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/node_api_jsrt.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,6 +2524,23 @@ napi_status napi_create_dataview(napi_env env,
25242524

25252525
JsValueRef jsArrayBuffer = reinterpret_cast<JsValueRef>(arraybuffer);
25262526

2527+
BYTE* unused = nullptr;
2528+
unsigned int bufferLength = 0;
2529+
2530+
CHECK_JSRT(JsGetArrayBufferStorage(
2531+
jsArrayBuffer,
2532+
&unused,
2533+
&bufferLength));
2534+
2535+
if (byte_length + byte_offset > bufferLength) {
2536+
napi_throw_range_error(
2537+
env,
2538+
"ERR_NAPI_INVALID_DATAVIEW_ARGS",
2539+
"byte_offset + byte_length should be less than or "
2540+
"equal to the size in bytes of the array passed in");
2541+
return napi_set_last_error(napi_pending_exception);
2542+
}
2543+
25272544
CHECK_JSRT(JsCreateDataView(
25282545
jsArrayBuffer,
25292546
static_cast<unsigned int>(byte_offset),

0 commit comments

Comments
 (0)