Integrated: JDK-8320570 NegativeArraySizeException decoding >1G UTF8 bytes with non-ascii characters

Jim Laskey jlaskey at openjdk.org
Wed Dec 6 21:57:48 UTC 2023


On Tue, 5 Dec 2023 14:57:09 GMT, Jim Laskey <jlaskey at openjdk.org> wrote:

> A regression is found in Java9+ creating String instance from UTF8 bytes, a side effect of string compactation https://openjdk.org/jeps/254 that changed the decoding logic. Specifically, when constructing a string from bytes: 
> 
> ``` 
> String str = new String(largeBytes, StandardCharsets.UTF_8); 
> ``` 
> 
> if the size of largeBytes is greater than 2^30 (>1 GB) but smaller than INT_MAX (2 GB), it fails on Java9+ (including 11, 17, 21, though the stack trace is slightly different, see below), regardless of jvm heap size. In Java8, it succeeded when jvm heap size is set to be sufficient.

This pull request has now been integrated.

Changeset: 82796bde
Author:    Jim Laskey <jlaskey at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/82796bdebbf56b98ec97a6d572ed68c2842f60c6
Stats:     82 lines in 2 files changed: 75 ins; 0 del; 7 mod

8320570: NegativeArraySizeException decoding >1G UTF8 bytes with non-ascii characters

Reviewed-by: rriggs

-------------

PR: https://git.openjdk.org/jdk/pull/16974


More information about the core-libs-dev mailing list