diff --git a/src/node_api.cc b/src/node_api.cc index 5a2dbb06b..235f3dbac 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -3255,6 +3255,14 @@ napi_status napi_create_dataview(napi_env env, RETURN_STATUS_IF_FALSE(env, value->IsArrayBuffer(), napi_invalid_arg); v8::Local buffer = value.As(); + if (byte_length + byte_offset > buffer->ByteLength()) { + 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(env, napi_generic_failure); + } v8::Local DataView = v8::DataView::New(buffer, byte_offset, byte_length);