[LANG-1397] WordUtils.wrap throws StringIndexOutOfBoundsException when

wrapLength is Integer.MAX_VALUE.
This commit is contained in:
Takanobu Asanuma 2018-05-18 11:44:37 -06:00 committed by Gary Gregory
parent bd4066eba8
commit 09ef69c5b5
3 changed files with 10 additions and 1 deletions

View File

@ -56,6 +56,7 @@ The <action> type attribute can be add,update,fix,remove.
<action issue="LANG-1371" type="fix" dev="pschumacher" due-to="Dmitry Ovchinnikov">Fix TypeUtils#parameterize to work correctly with narrower-typed array</action>
<action issue="LANG-1370" type="fix" dev="kinow" due-to="Andre Dieb">Fix EventCountCircuitBreaker increment batch</action>
<action issue="LANG-1385" type="fix" dev="ggregory" due-to="Rohan Padhye">NumberUtils.createNumber() throws StringIndexOutOfBoundsException instead of NumberFormatException</action>
<action issue="LANG-1397" type="fix" dev="ggregory" due-to="Takanobu Asanuma">WordUtils.wrap throws StringIndexOutOfBoundsException when wrapLength is Integer.MAX_VALUE.</action>
<action issue="LANG-1367" type="update" dev="ggregory" due-to="Gary Gregory">ObjectUtils.identityToString(Object) and friends should allocate builders and buffers with a size</action>
<action issue="LANG-1352" type="add" dev="pschumacher" due-to="Ruslan Sibgatullin">EnumUtils.getEnumIgnoreCase and isValidEnumIgnoreCase methods added</action>
<action issue="LANG-1372" type="add" dev="pschumacher" due-to="Sérgio Ozaki">Add ToStringSummary annotation</action>

View File

@ -288,7 +288,8 @@ public class WordUtils {
while (offset < inputLineLength) {
int spaceToWrapAt = -1;
Matcher matcher = patternToWrapOn.matcher(str.substring(offset, Math.min(offset + wrapLength + 1, inputLineLength)));
Matcher matcher = patternToWrapOn.matcher(
str.substring(offset, Math.min((int)Math.min(Integer.MAX_VALUE, offset + wrapLength + 1L), inputLineLength)));
if (matcher.find()) {
if (matcher.start() == 0) {
offset += matcher.end();

View File

@ -427,4 +427,11 @@ public class WordUtilsTest {
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",70);
}
@Test
public void testLANG1397() throws Exception {
// Prior to fix, this was throwing StringIndexOutOfBoundsException
WordUtils.wrap("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa "
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa "
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", Integer.MAX_VALUE);
}
}