Skip to content

Commit 17c74e5

Browse files
romandevmhdawson
authored andcommitted
n-api: RangeError in napi_create_dataview()
The API is required that `byte_length + byte_offset` is less than or equal to the size in bytes of the array passed in. If not, a RangeError exception is raised[1]. This is a partial cherry-pick from upstream[2]. [1] https://nodejs.org/api/n-api.html#n_api_napi_create_dataview [2] nodejs/node@2e329e9 PR-URL: #214 Reviewed-By: Michael Dawson <[email protected]>
1 parent 4058a29 commit 17c74e5

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/node_api.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3255,6 +3255,14 @@ napi_status napi_create_dataview(napi_env env,
32553255
RETURN_STATUS_IF_FALSE(env, value->IsArrayBuffer(), napi_invalid_arg);
32563256

32573257
v8::Local<v8::ArrayBuffer> buffer = value.As<v8::ArrayBuffer>();
3258+
if (byte_length + byte_offset > buffer->ByteLength()) {
3259+
napi_throw_range_error(
3260+
env,
3261+
"ERR_NAPI_INVALID_DATAVIEW_ARGS",
3262+
"byte_offset + byte_length should be less than or "
3263+
"equal to the size in bytes of the array passed in");
3264+
return napi_set_last_error(env, napi_generic_failure);
3265+
}
32583266
v8::Local<v8::DataView> DataView = v8::DataView::New(buffer, byte_offset,
32593267
byte_length);
32603268

0 commit comments

Comments
 (0)