[ 
https://issues.apache.org/jira/browse/LANG-1824?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Gary D. Gregory resolved LANG-1824.
-----------------------------------
    Fix Version/s: 3.21.0
       Resolution: Fixed

I merged the PR. Please verify your use case in git master and/or snapshot 
builds from 
[https://repository.apache.org/content/repositories/snapshots/org/apache/commons/commons-lang3/3.21.0-SNAPSHOT/]

TY!

> NegativeArraySizeException thrown from Strings.replace with larger replacement
> ------------------------------------------------------------------------------
>
>                 Key: LANG-1824
>                 URL: https://issues.apache.org/jira/browse/LANG-1824
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>    Affects Versions: 3.20.0
>            Reporter: Veijo Vainionpää
>            Priority: Major
>             Fix For: 3.21.0
>
>
> NegativeArraySizeException thrown from Strings.replace with larger 
> replacement when {{replacement.length() - searchString.length()}} is bigger 
> than 134217727 bytes (~132 MB).
> {{public String replace(final String text, String searchString, final String 
> replacement, int max) {}}
> {{...}}
> {{final int replLength = searchString.length();}}
> {{int increase = Math.max(replacement.length() - replLength, 0);}}
> {{increase *= max < 0 ? 16 : Math.min(max, 64);}}
> {{final StringBuilder buf = new StringBuilder(text.length() + increase);}}
> {{...}}
> {{}}}
> The main reason is that the integer overflows after multiplication.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to