-
Notifications
You must be signed in to change notification settings - Fork 683
Add new check for a special corner case to typedarray lastIndexOf #3156
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
Conversation
jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-prototype.c
Outdated
Show resolved
Hide resolved
1affd7d
to
b252eba
Compare
if (!ecma_number_is_nan (num_var) | ||
&& is_last_index_of | ||
&& num_var < 0 | ||
&& (uint32_t) abs((int) num_var) > length) |
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.
This is a bit complicated. Isn't the num_var > length
check enough here?
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.
Not really, because if the second argument is negative, than the normalized index is calculated this way: norm_index = length - abs (from_index). And since we return with uint32_t in the array_index_normalize method, if this negative argument's absolute value is greater than the length, the norm_index itself becomes negative, and this will result an underflow. So if we know, that the second argument is negative, and its absolute value is greater then the length, we should return -1, but if this absolute value is less then the length, we could calculate with it.
b252eba
to
096c956
Compare
Fixes jerryscript-project#3129 We need to check if we use the lastIndexOf method and if the second argument is a number, negative, and its absolute value is bigger than the length, then we should return with -1. JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu
096c956
to
ef0d06c
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
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
Fixes #3129
We need to check if we use the lastIndexOf method and if the second
argument is a number, negative, and its absolute value is bigger
than the length, then we should return with -1.
JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu