Skip to content

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

Merged
merged 1 commit into from
Sep 27, 2019

Conversation

szilagyiadam
Copy link
Contributor

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

@rerobika rerobika added bug Undesired behaviour ES2015 Related to ES2015 features labels Sep 24, 2019
if (!ecma_number_is_nan (num_var)
&& is_last_index_of
&& num_var < 0
&& (uint32_t) abs((int) num_var) > length)
Copy link
Member

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?

Copy link
Contributor Author

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.

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
Copy link
Member

@rerobika rerobika left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@dbatyai dbatyai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dbatyai dbatyai merged commit 711b06d into jerryscript-project:master Sep 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Undesired behaviour ES2015 Related to ES2015 features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

heap-buffer-overflow in ecma_get_typedarray_element
3 participants