-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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_dataview() with invalid range #17869
Conversation
src/node_api.cc
Outdated
"napi_create_dataview", | ||
"byte_offset + byte_length should be less than or " | ||
"equal to the size in bytes of the array passed in"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't there be some kind of early return in this case? Otherwise we still create the DataView instance & pass it in *result
... right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. I missed return
statement. :(
Done. Thank you for review.
594dcf2
to
7bbd2ff
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fact that V8 isn’t throwing an error on cases like this sounds like a bug to me, as the JS DataView constructor does throw. But, this LGTM.
Thank you for review. You're right. In JS code, [1] https://cs.chromium.org/chromium/src/v8/src/builtins/builtins-dataview.cc?sq=package:chromium&l=74 |
7bbd2ff
to
abc4e1a
Compare
Gentle ping :) |
src/node_api.cc
Outdated
if (byte_length + byte_offset > buffer->ByteLength()) { | ||
return napi_throw_range_error( | ||
env, | ||
"napi_create_dataview", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CODE passed in should be defined in https://github.com/nodejs/node/blob/master/lib/internal/errors.js right after ERR_NAPI_CONTS_PROTOTYPE_OBJECT, and I'd suggest it be ERR_NAPI_INVALID_DATAVIEW_ARGS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for review. Done.
Just one comment about how we define the error code but after that it fixed up it looks good. |
abc4e1a
to
d85f019
Compare
lib/internal/errors.js
Outdated
@@ -433,6 +433,8 @@ E('ERR_MODULE_RESOLUTION_LEGACY', '%s not found by import in %s.' + | |||
E('ERR_MULTIPLE_CALLBACK', 'Callback called multiple times'); | |||
E('ERR_NAPI_CONS_FUNCTION', 'Constructor must be a function'); | |||
E('ERR_NAPI_CONS_PROTOTYPE_OBJECT', 'Constructor.prototype must be an object'); | |||
E('ERR_NAPI_INVALID_DATAVIEW_ARGS', | |||
'Invalid arguments were passed to napi_create_dataview()'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The message here should match the message in src/node_api.cc. There will be a better way to handle errors on the native side but for now I think we want to make the messages the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have suggested that in the original comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for explanation.
I've addressed your comment in my latest patch.
d85f019
to
5fdd4ac
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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
5fdd4ac
to
2e329e9
Compare
@mhdawson I've just fixed the CI error in latest patch. Also, I tested it on my Mac and Linux. (Used this command |
"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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, a crash occurred because there was no this line.
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: #17869 Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]>
Landed in 91c1ccd |
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: #17869 Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]>
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: #17869 Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]>
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: nodejs#17869 Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]>
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: nodejs#17869 Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]>
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 Backport-PR-URL: #19447 PR-URL: #17869 Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]>
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 Backport-PR-URL: #19265 PR-URL: #17869 Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]>
The API is required that
byte_length + byte_offset
is less than orequal to the size in bytes of the array passed in. If not, a RangeError
exception is raised.
Refs: https://nodejs.org/api/n-api.html#n_api_napi_create_dataview
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
n-api