8297530: java.lang.IllegalArgumentException: Negative length on strings concatenation

Reviewed-by: enikitin, alanb
This commit is contained in:
Claes Redestad 2022-11-24 17:40:30 +00:00
parent 390e69ad06
commit 87d1097d9b
2 changed files with 141 additions and 2 deletions

View file

@ -434,8 +434,11 @@ final class StringConcatHelper {
@ForceInline
static byte[] newArray(long indexCoder) {
byte coder = (byte)(indexCoder >> 32);
int index = (int)indexCoder;
return (byte[]) UNSAFE.allocateUninitializedArray(byte.class, index << coder);
int index = ((int)indexCoder) << coder;
if (index < 0) {
throw new OutOfMemoryError("Overflow: String length out of range");
}
return (byte[]) UNSAFE.allocateUninitializedArray(byte.class, index);
}
/**