RFR: 8325002: Exceptions::fthrow needs to ensure it truncates to a valid utf8 string
David Holmes
dholmes at openjdk.org
Sat Jul 27 12:22:31 UTC 2024
On Fri, 26 Jul 2024 05:19:32 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:
>> Exceptions::fthrow uses a 1024 byte buffer to format the incoming exception message string, but this may not be large enough, leading to truncation. However, we should ensure we truncate to a valid UTF8 sequence.
>>
>> The process is explained in the code. Thanks to @RogerRiggs and @djelinski for their suggestions on how to tackle this.
>>
>> Testing:
>> - new gtest exercises the truncation code with the different possibilities for bad truncation
>> - tiers 1-3 sanity testing
>>
>> Thanks.
>
> src/hotspot/share/utilities/utf8.cpp line 407:
>
>> 405: // To avoid that the caller can choose to check for validity first.
>> 406: // The incoming buffer is still expected to be NUL-terminated.
>> 407: void UTF8::truncate_to_legal_utf8(unsigned char* buffer, int length) {
>
> Lets make buffer length size_t and avoid awkward casting
No this code uses `int` for length everywhere. Feel free to file a RFE to change it all.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20345#discussion_r1693949553
More information about the hotspot-dev
mailing list