summaryrefslogtreecommitdiff
path: root/src/node_api.cc
diff options
context:
space:
mode:
authorJinho Bang <zino@chromium.org>2017-12-26 23:20:39 +0900
committerJames M Snell <jasnell@gmail.com>2018-01-09 16:20:19 -0800
commit91c1ccd84f5d36906e2cd498f0a49318ebce68b9 (patch)
treec8fbc8f2f7503212b5d57e37d28ad3fab51b8073 /src/node_api.cc
parent71203f5230fbe0f6d0e73793f5b7767378325875 (diff)
downloadandroid-node-v8-91c1ccd84f5d36906e2cd498f0a49318ebce68b9.tar.gz
android-node-v8-91c1ccd84f5d36906e2cd498f0a49318ebce68b9.tar.bz2
android-node-v8-91c1ccd84f5d36906e2cd498f0a49318ebce68b9.zip
n-api: throw RangeError in napi_create_dataview() with invalid range
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]. [1] https://nodejs.org/api/n-api.html#n_api_napi_create_dataview PR-URL: https://github.com/nodejs/node/pull/17869 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_api.cc')
-rw-r--r--src/node_api.cc8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/node_api.cc b/src/node_api.cc
index ac0b0959b5..095f98f64f 100644
--- a/src/node_api.cc
+++ b/src/node_api.cc
@@ -3170,6 +3170,14 @@ napi_status napi_create_dataview(napi_env env,
RETURN_STATUS_IF_FALSE(env, value->IsArrayBuffer(), napi_invalid_arg);
v8::Local<v8::ArrayBuffer> buffer = value.As<v8::ArrayBuffer>();
+ 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_pending_exception);
+ }
v8::Local<v8::DataView> DataView = v8::DataView::New(buffer, byte_offset,
byte_length);