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

Commit

Permalink
napi: add range check to jsrt version of napi_create_dataview
Browse files Browse the repository at this point in the history
  • Loading branch information
boingoing authored and kfarnung committed Mar 7, 2018
1 parent 5bed491 commit 3d3f493
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/node_api_jsrt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2524,6 +2524,23 @@ napi_status napi_create_dataview(napi_env env,

JsValueRef jsArrayBuffer = reinterpret_cast<JsValueRef>(arraybuffer);

BYTE* unused = nullptr;
unsigned int bufferLength = 0;

CHECK_JSRT(JsGetArrayBufferStorage(
jsArrayBuffer,
&unused,
&bufferLength));

if (byte_length + byte_offset > bufferLength) {
napi_throw_range_error(
env,
"ERR_NAPI_INVALID_DATAVIEW_ARGS",
"byte_offset + byte_length should be less than or "
"equal to the size in bytes of the array passed in");
return napi_set_last_error(napi_pending_exception);
}

CHECK_JSRT(JsCreateDataView(
jsArrayBuffer,
static_cast<unsigned int>(byte_offset),
Expand Down

0 comments on commit 3d3f493

Please sign in to comment.