[jdk17u-dev] Integrated: 8320570: NegativeArraySizeException decoding >1G UTF8 bytes with non-ascii characters

Amos Shi ashi at openjdk.org
Tue Apr 9 18:21:17 UTC 2024


On Fri, 8 Mar 2024 23:02:11 GMT, Amos Shi <ashi at openjdk.org> wrote:

> Backport of [JDK-8320570](https://bugs.openjdk.org/browse/JDK-8320570)
> - `NegativeSize.java` - Clean backport
> - `String.java` - 3 sections change are unclean, the rest are clean. Details as bellow.
> - This PR contains 2 commits
>   - The commit 1: is a clean backport part
>   - The commit 2: is a manual fix of the following 3 sections, 
>     - Replace all `new byte[length << 1]` as `StringUTF16.newBytesFor(length)`
> 
> 
> @@ -592,7 +592,7 @@
>                      this.coder = LATIN1;
>                      return;
>                  }
> -                byte[] utf16 = new byte[length << 1];
> +                byte[] utf16 = StringUTF16.newBytesFor(length);
>                  StringLatin1.inflate(latin1, 0, utf16, 0, dp);
>                  dp = decodeUTF8_UTF16(latin1, sp, length, utf16, dp, true);
>                  if (dp != length) {
> 
> 
> 
> @@ -601,7 +601,7 @@
>                  this.value = utf16;
>                  this.coder = UTF16;
>              } else { // !COMPACT_STRINGS
> -                byte[] dst = new byte[length << 1];
> +                byte[] dst = StringUTF16.newBytesFor(length);
>                  int dp = decodeUTF8_UTF16(bytes, offset, offset + length, dst, 0, true);
>                  if (dp != length) {
>                      dst = Arrays.copyOf(dst, dp << 1);
> 
> 
> 
> @@ -730,15 +730,15 @@
>                  return new String(dst, LATIN1);
>              }
>              if (dp == 0) {
> -                dst = new byte[length << 1];
> +                dst = StringUTF16.newBytesFor(length);
>              } else {
> -                byte[] buf = new byte[length << 1];
> +                byte[] buf = StringUTF16.newBytesFor(length);
>                  StringLatin1.inflate(dst, 0, buf, 0, dp);
>                  dst = buf;
>              }
>              dp = decodeUTF8_UTF16(bytes, offset, sl, dst, dp, false);
>          } else { // !COMPACT_STRINGS
> -            dst = new byte[length << 1];
> +            dst = StringUTF16.newBytesFor(length);
>              dp = decodeUTF8_UTF16(bytes, offset, offset + length, dst, 0, false);
>          }
>          if (dp != length) {
> 
> 
> - 💚 So this PR can be considered as `semantics clean`
> 
> 
> Testing
> - Local: 
>   - Passed on MacOS M1 laptop
>     - `test/jdk/java/lang/String/CompactString/NegativeSize.java` - Test results: passed: 1
>   - Passed on Windows 11
>     - `test/jdk/java/lang/String/CompactString/NegativeSize.java` - Test results: passed: 1
> 
> Processor	12th Gen Intel(R) Core(TM) i7-12800H   2.40 GHz
> Installed RAM	64.0 GB (63.7 GB usable)
> System type	64-bit operating system, x64...

This pull request has now been integrated.

Changeset: fc01ffe9
Author:    Amos Shi <ashi at openjdk.org>
URL:       https://git.openjdk.org/jdk17u-dev/commit/fc01ffe952f781f7510575b015c64cfc6b7431ed
Stats:     82 lines in 2 files changed: 76 ins; 0 del; 6 mod

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

Reviewed-by: phh
Backport-of: 82796bdebbf56b98ec97a6d572ed68c2842f60c6

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

PR: https://git.openjdk.org/jdk17u-dev/pull/2279


More information about the jdk-updates-dev mailing list