simpleqt opened a new pull request, #1878:
URL: https://github.com/apache/commons-lang/pull/1878
The `StringUtils.join` overloads that take a start and an end index compute
the range length with `int` arithmetic, so an extreme `endIndex` overflows the
subtraction and bypasses the documented empty-range guard:
```java
String[] a = {"a", "b", "c"};
StringUtils.join(a, "--", 1, Integer.MIN_VALUE); // "b--c", expected
""
StringUtils.join(new int[] {1, 2, 3}, ';', 1, Integer.MIN_VALUE); //
NegativeArraySizeException: -13
```
`1 - Integer.MIN_VALUE` overflows to `2147483647`, which passes `count <=
0`, so a suffix is joined, or the capacity is sized from the overflowed value.
This affects the eight primitive-array overloads, the two `List` overloads and
the `Object[]` overload.
The range length is computed in `long` at all eleven sites, so the guard
sees a negative count and returns the documented empty string. The `(int)`
capacity argument stays bounded because `checkFromToIndex` rejects a negative
`startIndex` and an `endIndex` past the array length, so a positive count never
exceeds the array length.
## Test
`StringUtilsTest.testJoinRangeExtremeEndIndexOverflow` covers the
`Object[]`, `List`, `char` and `String` delimiter variants and all eight
primitive-array overloads, plus a non-overflowing reversed range and a normal
range.
- with the source change reverted (on this head): `mvn -B -o -ntp
"-Dtest=StringUtilsTest#testJoinRangeExtremeEndIndexOverflow" test` -> 1 run, 1
failure, `expected: <> but was: <b--c>`
- with the change: same command -> 1 run, 0 failures;
`-Dtest=StringUtilsTest` -> 184 run, 0 failures, 1 skipped; full module `mvn -B
-o -ntp test` -> 107,567 run, 0 failures, 18 skipped (baseline on the base
commit before the change: 107,566 run, 18 skipped)
Rebased on master `924eb8d` after the capacity-overflow work in `a5ff3be`;
that commit changed the capacity estimate, not the range length, so this fix is
the remaining half of the same overflow class. The `src/changes/changes.xml`
action is added to the unreleased release block.
The commit carries an `Assisted-By:` trailer, as `AGENTS.md` asks.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]