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

Chen Liang liach at openjdk.org
Tue Sep 23 12:53:25 UTC 2025


On Tue, 23 Sep 2025 06:58:18 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 with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 10 additional commits since the last revision:
> 
>  - optimize test
>  - Merge remote-tracking branch 'upstream/master' into 8366421
>  - Update and rename TestUtfLen.java to ModifiedUtfTest.java
>    
>    rename test
>  - Update TestUtfLen.java
>    
>    fix a small error
>  - Update TestUtfLen.java
>    
>    fix format error
>  - Update TestUtfLen.java
>    
>    Optimize regression test
>  - Update TestUtfLen.java
>    
>    update regression test
>  - add regression test
>  - Merge remote-tracking branch 'upstream/master' into 8366421
>  - Change return type of utfLen to long to prevent overflow

Though I think the tests for DOS/OOS/BufWriter should be located in their own tests instead of ModifiedUtfTest, this is okay.

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

Marked as reviewed by liach (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/27285#pullrequestreview-3257853133


More information about the core-libs-dev mailing list