Repository: commons-lang Updated Branches: refs/heads/master bd4066eba -> 09ef69c5b
[LANG-1397] WordUtils.wrap throws StringIndexOutOfBoundsException when wrapLength is Integer.MAX_VALUE. Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/09ef69c5 Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/09ef69c5 Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/09ef69c5 Branch: refs/heads/master Commit: 09ef69c5b51115300da6df43690cd455d83c8027 Parents: bd4066e Author: Takanobu Asanuma <tasan...@yahoo-corp.jp> Authored: Fri May 18 11:44:37 2018 -0600 Committer: Gary Gregory <garydgreg...@gmail.com> Committed: Fri May 18 11:44:37 2018 -0600 ---------------------------------------------------------------------- src/changes/changes.xml | 1 + src/main/java/org/apache/commons/lang3/text/WordUtils.java | 3 ++- .../java/org/apache/commons/lang3/text/WordUtilsTest.java | 7 +++++++ 3 files changed, 10 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-lang/blob/09ef69c5/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 5960d00..64469cf 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -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> http://git-wip-us.apache.org/repos/asf/commons-lang/blob/09ef69c5/src/main/java/org/apache/commons/lang3/text/WordUtils.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/lang3/text/WordUtils.java b/src/main/java/org/apache/commons/lang3/text/WordUtils.java index b4c5999..a42f9d6 100644 --- a/src/main/java/org/apache/commons/lang3/text/WordUtils.java +++ b/src/main/java/org/apache/commons/lang3/text/WordUtils.java @@ -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(); http://git-wip-us.apache.org/repos/asf/commons-lang/blob/09ef69c5/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java b/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java index b311b30..d99a97b 100644 --- a/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java @@ -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); + } }