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

Ioi Lam iklam at openjdk.org
Mon Oct 20 17:11: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.

> Dear @iklam , in #26955, it is suggested to use `uintptr_t` for addresses in pointer arithmetics and cast them to `address` when we pass them into functions. There are some of this conversions in related code here, do you want me to do this or as a separate RFE?

I think we should probably do that in a separate RFE. The CDS code has a mixed use of intptr_t, address and char* for addresses. We should probably change all of them to a single type, and I agree that  intptr_t is the best of the three.

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

> 1045: address ArchiveBuilder::offset_to_buffered_address(u4 offset) const {
> 1046:   // As zero is allowed for _requested_static_archive_bottom, use integer arithmetic to avoid UB pointer arithmetic.
> 1047:   address requested_addr = (address)((uintptr_t)_requested_static_archive_bottom + offset);

We should avoid this problem altogether with this:


- address requested_addr = _requested_static_archive_bottom + offset;
- address buffered_addr = requested_addr - _buffer_to_requested_delta;
- address buffered_addr = _buffer_bottom + offset;

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

PR Comment: https://git.openjdk.org/jdk/pull/26983#issuecomment-3423004461
PR Review Comment: https://git.openjdk.org/jdk/pull/26983#discussion_r2445611871


More information about the hotspot-runtime-dev mailing list