You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "alhudz (via GitHub)" <gi...@apache.org> on 2026/07/16 11:36:58 UTC
[PR] fix ArrayUtils.reverse range underflow on Integer.MIN_VALUE end [commons-lang]
alhudz opened a new pull request, #1750:
URL: https://github.com/apache/commons-lang/pull/1750
Repro: `ArrayUtils.reverse(new int[]{1, 2, 3}, 0, Integer.MIN_VALUE)`.
Expected: no change, since the `endIndexExclusive` Javadoc documents an undervalue `< start index` as no change.
Actual: `ArrayIndexOutOfBoundsException: Index 2147483647 out of bounds for length 3`.
Cause: `Math.min(array.length, endIndexExclusive) - 1` keeps `Integer.MIN_VALUE` and the `- 1` underflows to `Integer.MAX_VALUE`, so the `while (j > i)` loop indexes past the array. All nine primitive and `Object` range overloads share the line.
Fix: clamp the end to zero before the decrement with the existing `max0` helper, as the sibling `subarray` and `shift` methods already do. Every other negative end was already a no-op, so valid ranges are unchanged.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix ArrayUtils.reverse range underflow on Integer.MIN_VALUE end [commons-lang]
Posted by "alhudz (via GitHub)" <gi...@apache.org>.
alhudz commented on PR #1750:
URL: https://github.com/apache/commons-lang/pull/1750#issuecomment-5010650141
Thanks for the merge. I went back over the class with the same `Integer.MIN_VALUE`/`MAX_VALUE` probes and didn't find another escape: `subarray` already clamps with `max0`, `shift` returns early on `endIndexExclusive <= 0` before any subtraction, `swap` runs `max0` on both offsets and bounds `len` by the remaining lengths, and `indexOf`/`lastIndexOf` (including the NaN and tolerance variants) either clamp or bail on a negative start. `add(index)`, `insert` and `remove` throw `IndexOutOfBoundsException` by documented contract, so `reverse` looks to have been the only spot where an extreme value got past the clamps.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix ArrayUtils.reverse range underflow on Integer.MIN_VALUE end [commons-lang]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on PR #1750:
URL: https://github.com/apache/commons-lang/pull/1750#issuecomment-5004074263
Good find @alhudz, merged 🚀 Do you see any other similar index issue in this class?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix ArrayUtils.reverse range underflow on Integer.MIN_VALUE end [commons-lang]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on PR #1750:
URL: https://github.com/apache/commons-lang/pull/1750#issuecomment-5011259911
@alhudz thank you for checking.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix ArrayUtils.reverse range underflow on Integer.MIN_VALUE end [commons-lang]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory merged PR #1750:
URL: https://github.com/apache/commons-lang/pull/1750
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org