RFR: 8325002: Exceptions::fthrow needs to ensure it truncates to a valid utf8 string [v2]
Daniel Jeliński
djelinski at openjdk.org
Mon Jul 29 13:28:32 UTC 2024
On Mon, 29 Jul 2024 09:54:09 GMT, David Holmes <dholmes 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.
>
> David Holmes has updated the pull request incrementally with three additional commits since the last revision:
>
> - Fix logic for 4th byte of 6.
> - Fix logic error and typo
> - Ensure the buffer is > 5 bytes
src/hotspot/share/utilities/exceptions.cpp line 275:
> 273: // we may also have a truncated UTF-8 sequence. In such cases we need to fix the buffer so the UTF-8
> 274: // sequence is valid.
> 275: if ((ret == -1 || ret >= max_msg_size) && strlen(msg) > 0) {
Do we need to check if `strlen(msg) == max_msg_size - 1`? If strlen is shorter, the bytes between the null terminator and max_msg_size are undefined, which might trigger an assertion while truncating.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20345#discussion_r1695241148
More information about the hotspot-dev
mailing list