-
Notifications
You must be signed in to change notification settings - Fork 721
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
Fix String.indexOf corner case where start == Integer.MAX_VALUE - 1 #6403
Fix String.indexOf corner case where start == Integer.MAX_VALUE - 1 #6403
Conversation
41ebfdf
to
91a0381
Compare
91a0381
to
b2bd8e0
Compare
When calling the `java.lang.String.indexOf` API with a `String` argument and passing the starting offset to be `Integer.MAX_VALUE - 1` we encounter an overflow when we test for the following condition: ``` if (start + s2len > s1len) { return -1; } ``` This if statement checks that the there are enough characters from the starting position the user specified for the substring to occur. i.e. if the source string is "abcdefg" and the substring is "fghijk" and start offset is 2 then because the length of the source string is 7 and the length of the substring is 6, 2 + 6 > 7 so it is impossible for the substring to be contained within the source string. We can return -1 immediately. The problem with the if statement is if we pass a starting offset to be `Integer.MAX_VALUE - 1` which is a valid input the addition in the if statement overflows and we never enter the if block, even though we should have had there been no overflow. This causes us to call the JITHelpers intrinsic which has implicit assumptions about the arguments and we end up dereferencing memory outside of the heap. This commit fixes the overflow by using subtraction. We also take this opportunity to document the implicit assumptions on the JIT intrinsics that we make use of. Signed-off-by: Filip Jeremic <fjeremic@ca.ibm.com>
Use the same function name across all codegens currently inlining `IntrinsicIndexOf` and standardize the call argument names to be identical to that of the Java code. Signed-off-by: Filip Jeremic <fjeremic@ca.ibm.com>
Jenkins test sanity all jdk8 |
x changes and common code changes look good - I'll leave it to someone else to verify the POWER and z changes since I'm not an expert on those areas. |
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.
Refactoring done in the Z codegen evaluator looks good to me.
@aviansie-ben could you please review Power changes? |
Looks fine to me. Just wanted @aviansie-ben to take a look at the Power changes. |
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.
Power codegen changes look good to me
I'll go ahead and merge since it seems everyone has approved now. |
When calling the
java.lang.String.indexOf
API with aString
argument and passing the starting offset to be
Integer.MAX_VALUE - 1
we encounter an overflow when we test for the following condition:
This if statement checks that the there are enough characters from the
starting position the user specified for the substring to occur. i.e.
if the source string is "abcdefg" and the substring is "fghijk" and
start offset is 2 then because the length of the source string is 7 and
the length of the substring is 6, 2 + 6 > 7 so it is impossible for the
substring to be contained within the source string. We can return -1
immediately.
The problem with the if statement is if we pass a starting offset to be
Integer.MAX_VALUE - 1
which is a valid input the addition in the ifstatement overflows and we never enter the if block, even though we
should have had there been no overflow. This causes us to call the
JITHelpers intrinsic which has implicit assumptions about the arguments
and we end up dereferencing memory outside of the heap.
This commit fixes the overflow by using subtraction. We also take this
opportunity to document the implicit assumptions on the JIT intrinsics
that we make use of.
Signed-off-by: Filip Jeremic fjeremic@ca.ibm.com