8311906: Improve robustness of String constructors with mutable array inputs

Co-authored-by: Damon Fenacci <dfenacci@openjdk.org>
Co-authored-by: Claes Redestad <redestad@openjdk.org>
Co-authored-by: Amit Kumar <amitkumar@openjdk.org>
Co-authored-by: Martin Doerr <mdoerr@openjdk.org>
Reviewed-by: rgiulietti, thartmann, redestad, dfenacci
This commit is contained in:
Roger Riggs 2023-12-04 18:28:59 +00:00
parent 316b78336c
commit 155abc576a
15 changed files with 1300 additions and 248 deletions

View file

@ -47,8 +47,12 @@ final class StringLatin1 {
return (char)(value[index] & 0xff);
}
public static boolean canEncode(char cp) {
return cp <= 0xff;
}
public static boolean canEncode(int cp) {
return cp >>> 8 == 0;
return cp >=0 && cp <= 0xff;
}
public static int length(byte[] value) {