RFR: 8366062: [ubsan] add non-zero offset to nullptr in cds/archiveBuilder.cpp [v6]

Ioi Lam iklam at openjdk.org
Mon Oct 20 16:59:08 UTC 2025


On Wed, 17 Sep 2025 09:53:28 GMT, Afshin Zafari <azafari at openjdk.org> wrote:

>> It is acceptable that the `SharedBaseAddress` option gets `0` at command line. The corresponding pointer arithmetic with `0` (`nullptr`) in archiveBuilder is UB.
>> Specific casts are used to avoid UBSAN error.
>> 
>> Tests:
>> linux-x64-debug: tier1 passed
>
> Afshin Zafari has updated the pull request incrementally with one additional commit since the last revision:
> 
>   fix after wrong merge.

src/hotspot/share/cds/archiveBuilder.cpp line 1116:

> 1114:     // As zero is allowed for new_bottom, use integer arithmetic to avoid UB pointer arithmetic.
> 1115:     address new_bottom = (address)((uintptr_t)bottom + _buffer_to_requested_delta);
> 1116:     address new_top = (address)((uintptr_t)top + _buffer_to_requested_delta);

In these two lines, `new_top`, `top` and `bottom` are never zeros. The only address that may be zero is `new_bottom`.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/26983#discussion_r2445590051


More information about the hotspot-runtime-dev mailing list