Veijo Vainionpää created LANG-1824:
--------------------------------------

             Summary: 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ää


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);}}
{color:#de350b}{{   }}{{increase *= max < 0 ? 16 : Math.min(max, 64);}}
{{{color:#172b4d}   final StringBuilder buf = new StringBuilder(text.length() + 
increase);
   ...{color}}}{color}

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