RFR: 8325002: Exceptions::fthrow needs to ensure it truncates to a valid utf8 string [v5]
David Holmes
dholmes at openjdk.org
Tue Jul 30 12:34:33 UTC 2024
On Tue, 30 Jul 2024 08:39:51 GMT, Daniel Jeliński <djelinski at openjdk.org> wrote:
>> David Holmes has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Fix off-by-one error
>
> src/hotspot/share/utilities/exceptions.cpp line 278:
>
>> 276: if (ret == -1 || ret >= max_msg_size) {
>> 277: int len = (int) strlen(msg);
>> 278: if (len > 0) {
>
> `truncate` asserts that len>5, you might need to adjust that.
We know we only got here because the message was either huge (-1) or > 1K. We only get a zero length if we got -1 and are on Windows. Any length < max_msg_size means we got -1 and are on macOS and we have truncated prior to the conversion that caused the INT_MAX overflow. In theory it could be a single "%s" format but in practice we don't call fthrow that way. Also if we got the -1 then there are actually very few circumstances that can get us to this point because it needs to be an exception message that can relate to huge strings (which at the moment is trying to look up a class with an illegally long name - something that will soon be handled on the Java side before we get to the VM.)
So if we somehow were to trigger the len>5 assert, that is fine as it indicates something unusual/unexpected that we want to catch.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20345#discussion_r1696883436
More information about the hotspot-dev
mailing list