diff options
author | Jinho Bang <zino@chromium.org> | 2018-01-08 23:37:27 +0900 |
---|---|---|
committer | Michael Dawson <michael_dawson@ca.ibm.com> | 2018-01-16 15:22:36 -0500 |
commit | 316b5efd6b02379a490ce62c31a13122729ff1dd (patch) | |
tree | 39db3752d7b7f7858dfc8bf38f0e31eda0b6e8bf /doc | |
parent | 4319780389badf4e173f57408b42949a2841a188 (diff) | |
download | android-node-v8-316b5efd6b02379a490ce62c31a13122729ff1dd.tar.gz android-node-v8-316b5efd6b02379a490ce62c31a13122729ff1dd.tar.bz2 android-node-v8-316b5efd6b02379a490ce62c31a13122729ff1dd.zip |
n-api: throw RangeError napi_create_typedarray()
According to the ECMA spec, we should throw a RangeError in the
following cases:
- `(length * elementSize) + offset` > the size of the array passed in
- `offset % elementSize` != `0`
In the current implementation, this check was omitted. So, the following
code will cause a crash.
```
napi_create_typedarray(env, napi_uint16_array, 2 /* length */,
buffer, 1 /* byte_offset */, &output_array);
```
This change fixes the problem and write some related tests.
Refs:
https://tc39.github.io/ecma262/#sec-typedarray-buffer-byteoffset-length
PR-URL: https://github.com/nodejs/node/pull/18037
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Diffstat (limited to 'doc')
-rw-r--r-- | doc/api/errors.md | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/doc/api/errors.md b/doc/api/errors.md index 32281dfe2d..4bfce90bce 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -1328,6 +1328,18 @@ While using `N-API`, `Constructor.prototype` was not an object. While calling `napi_create_dataview()`, a given `offset` was outside the bounds of the dataview or `offset + length` was larger than a length of given `buffer`. +<a id="ERR_NAPI_INVALID_TYPEDARRAY_ALIGNMENT"></a> +### ERR_NAPI_INVALID_TYPEDARRAY_ALIGNMENT + +While calling `napi_create_typedarray()`, the provided `offset` was not a +multiple of the element size. + +<a id="ERR_NAPI_INVALID_TYPEDARRAY_LENGTH"></a> +### ERR_NAPI_INVALID_TYPEDARRAY_LENGTH + +While calling `napi_create_typedarray()`, `(length * size_of_element) + +byte_offset` was larger than the length of given `buffer`. + <a id="ERR_NO_CRYPTO"></a> ### ERR_NO_CRYPTO |