Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

n-api: throw RangeError in napi_create_typedarray() with invalid args #18037

Closed
wants to merge 1 commit into from

Commits on Jan 14, 2018

  1. n-api: throw RangeError in napi_create_typedarray() with invalid args

    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
    romandev committed Jan 14, 2018
    Configuration menu
    Copy the full SHA
    3e6d561 View commit details
    Browse the repository at this point in the history