RFR: 8366421: ModifiedUtf.utfLen may overflow for giant string [v6]

Roger Riggs rriggs at openjdk.org
Mon Sep 22 20:35:51 UTC 2025


On Sun, 21 Sep 2025 00:18:59 GMT, Guanqiang Han <ghan at openjdk.org> wrote:

>> Please review this patch.
>> 
>> **Description:**
>> 
>> Currently, ModifiedUtf.utfLen returns a signed int. For very large strings, this may overflow and produce negative values, leading to incorrect behavior in code that relies on the UTF length. This patch changes the return type to long, which fully resolves the issue and allows safe handling of giant strings.
>> 
>> **Test:**
>> 
>> GHA
>
> Guanqiang Han has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Update and rename TestUtfLen.java to ModifiedUtfTest.java
>   
>   rename test

src/java.base/share/classes/java/io/ObjectOutputStream.java line 1909:

> 1907:                     writeByte(TC_STRING);
> 1908:                 }
> 1909:                 writeShort((int)utflen);

This would seem more consistent if the cast was to (short).

test/jdk/jdk/internal/util/ModifiedUtfTest.java line 59:

> 57:    */
> 58:   static class HeaderCaptureOutputStream extends OutputStream {
> 59:     private byte[] head;

Indentation of java code is 4 spaces in OpenJDK.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/27285#discussion_r2369932520
PR Review Comment: https://git.openjdk.org/jdk/pull/27285#discussion_r2370000908


More information about the core-libs-dev mailing list