-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[LANG-1801] Fix RandomStringUtils.random() does not strictly validate start/end when chars != null, causing potential IndexOutOfBoundsException #1521
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
base: master
Are you sure you want to change the base?
Conversation
…chars != null, causing potential IndexOutOfBoundsException
|
Hi maintainers, I have prepared a fix to the problem of the method RandomStringUtils.random(), that:
Would you be open to accepting a pull request with this fix? Thank you for your time and for maintaining this excellent library! Best regards, |
…utOfBoundsException
|
Hello @theodoral22 |
|
Hi @garydgregory |
|
Hello @IcoreE |
| assertIllegalArgumentException(() -> RandomStringUtils.random(8, 32, 48, false, true)); | ||
| assertIllegalArgumentException(() -> RandomStringUtils.random(8, 32, 65, true, false)); | ||
| assertIllegalArgumentException(() -> RandomStringUtils.random(1, Integer.MIN_VALUE, -10, false, false, null)); | ||
| assertIllegalArgumentException(() -> RandomStringUtils.random(2, 5, 6, false, false, new char[] { 'a', 'b', 'c', 'd' }, new Random())); |
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 test should cover checks for end and start both separately and together.
Also should check that the correct messages are generated.
When a custom character array (chars != null) is supplied to RandomStringUtils.random(), the method does not strictly check that the start and end parameters fall within the valid bounds of the chars array.
As a result, if start or end exceeds chars.length, the method may generate a random index outside the array range, leading to an unexpected ArrayIndexOutOfBoundsException.
This fails the method contract and causes unpredictable runtime errors.
Actual:
Throws ArrayIndexOutOfBoundsException
Expected:
Throw IllegalArgumentException indicating invalid start/end range when chars != null
my issue @garydgregory