-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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 CharArraysTests.testConstantTimeEquals() #47346
Conversation
Pinging @elastic/es-core-infra |
randomAlphaOfLengthNotBeginningWith(value.substring(0, 1), value.length(), value.length())); | ||
assertFalse("value: " + value + ", other: " + other, CharArrays.constantTimeEquals(value, other)); | ||
assertFalse(CharArrays.constantTimeEquals(value.toCharArray(), other.toCharArray())); | ||
final int length = value.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.
I don't have strong feeling about it, but might be more straight forward to make sure this never happens on line 70 above.
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.
Well, I think this method must support empty strings/char arrays so... :)
The change #47238 fixed a first issue (#47076) but introduced another one that can be reproduced using: org.elasticsearch.common.CharArraysTests > testConstantTimeEquals FAILED java.lang.StringIndexOutOfBoundsException: String index out of range: 1 at __randomizedtesting.SeedInfo.seed([DFCA64FE2C786BE3:ED987E883715C63B]:0) at java.lang.String.substring(String.java:1963) at org.elasticsearch.common.CharArraysTests.testConstantTimeEquals(CharArraysTests.java:74) REPRODUCE WITH: ./gradlew ':libs:elasticsearch-core:test' --tests "org.elasticsearch.common.CharArraysTests.testConstantTimeEquals" -Dtests.seed=DFCA64FE2C786BE3 -Dtests.security.manager=true -Dtests.locale=fr-CA -Dtests.timezone=Pacific/Johnston -Dcompiler.java=12 -Druntime.java=8 that happens when the first randomized string has a length of 0.
The change #47238 fixed a first issue (#47076) but introduced another one that can be reproduced using: org.elasticsearch.common.CharArraysTests > testConstantTimeEquals FAILED java.lang.StringIndexOutOfBoundsException: String index out of range: 1 at __randomizedtesting.SeedInfo.seed([DFCA64FE2C786BE3:ED987E883715C63B]:0) at java.lang.String.substring(String.java:1963) at org.elasticsearch.common.CharArraysTests.testConstantTimeEquals(CharArraysTests.java:74) REPRODUCE WITH: ./gradlew ':libs:elasticsearch-core:test' --tests "org.elasticsearch.common.CharArraysTests.testConstantTimeEquals" -Dtests.seed=DFCA64FE2C786BE3 -Dtests.security.manager=true -Dtests.locale=fr-CA -Dtests.timezone=Pacific/Johnston -Dcompiler.java=12 -Druntime.java=8 that happens when the first randomized string has a length of 0.
Thanks @atorok |
The change elastic#47238 fixed a first issue (elastic#47076) but introduced another one that can be reproduced using: org.elasticsearch.common.CharArraysTests > testConstantTimeEquals FAILED java.lang.StringIndexOutOfBoundsException: String index out of range: 1 at __randomizedtesting.SeedInfo.seed([DFCA64FE2C786BE3:ED987E883715C63B]:0) at java.lang.String.substring(String.java:1963) at org.elasticsearch.common.CharArraysTests.testConstantTimeEquals(CharArraysTests.java:74) REPRODUCE WITH: ./gradlew ':libs:elasticsearch-core:test' --tests "org.elasticsearch.common.CharArraysTests.testConstantTimeEquals" -Dtests.seed=DFCA64FE2C786BE3 -Dtests.security.manager=true -Dtests.locale=fr-CA -Dtests.timezone=Pacific/Johnston -Dcompiler.java=12 -Druntime.java=8 that happens when the first randomized string has a length of 0.
…67168) * Ensure char array test uses different values (#47238) The test of constantTimeEquals could get unlucky and randomly produce the same two strings. This commit tweaks the test to ensure the two string are unique, and the loop inside constantTimeEquals is actually executed (which requires the strings be of the same length). * Fix CharArraysTests.testConstantTimeEquals() (#47346) The change #47238 fixed a first issue (#47076) but introduced another one that can be reproduced using: org.elasticsearch.common.CharArraysTests > testConstantTimeEquals FAILED java.lang.StringIndexOutOfBoundsException: String index out of range: 1 at __randomizedtesting.SeedInfo.seed([DFCA64FE2C786BE3:ED987E883715C63B]:0) at java.lang.String.substring(String.java:1963) at org.elasticsearch.common.CharArraysTests.testConstantTimeEquals(CharArraysTests.java:74) REPRODUCE WITH: ./gradlew ':libs:elasticsearch-core:test' --tests "org.elasticsearch.common.CharArraysTests.testConstantTimeEquals" -Dtests.seed=DFCA64FE2C786BE3 -Dtests.security.manager=true -Dtests.locale=fr-CA -Dtests.timezone=Pacific/Johnston -Dcompiler.java=12 -Druntime.java=8 that happens when the first randomized string has a length of 0. Co-authored-by: Ryan Ernst <[email protected]> Co-authored-by: Tanguy Leroux <[email protected]>
The change #47238 fixed a first issue (#47076) but introduced another one that can be reproduced using:
that happens when the first randomized string has a length of 0.