8370493: [ubsan] aotMapLogger.cpp:864:44: runtime error: applying non-zero offset NNNNN to null pointer

This commit is contained in:
Matias Saavedra Silva 2026-07-21 14:46:11 -04:00
parent 5b3456ce70
commit 68bf88e371
3 changed files with 13 additions and 6 deletions

View File

@ -27,6 +27,7 @@
#include "cds/aotMappedHeapWriter.hpp"
#include "cds/aotStreamedHeapLoader.hpp"
#include "cds/aotStreamedHeapWriter.hpp"
#include "cds/archiveUtils.hpp"
#include "cds/cdsConfig.hpp"
#include "cds/filemap.hpp"
#include "classfile/moduleEntry.hpp"
@ -879,7 +880,7 @@ void AOTMapLogger::runtime_log_heap_region(FileMapInfo* mapinfo) {
}
address requested_base = UseCompressedOops ? (address)mapinfo->narrow_oop_base() : AOTMappedHeapLoader::heap_region_requested_address(mapinfo);
address requested_start = requested_base + r->mapping_offset();
address requested_start = ArchiveUtils::offset_to_requested_addr(requested_base, r->mapping_offset());
log_region_range("heap", buffer_start, buffer_end, requested_start);
log_archived_objects(AOTMappedHeapLoader::oop_iterator(mapinfo, buffer_start, buffer_end));
}

View File

@ -367,7 +367,7 @@ address ArchiveBuilder::reserve_buffer() {
size_t static_archive_size = _mapped_static_archive_top - _mapped_static_archive_bottom;
// At run time, we will mmap the dynamic archive at my_archive_requested_bottom
_requested_static_archive_top = _requested_static_archive_bottom + static_archive_size;
_requested_static_archive_top = ArchiveUtils::offset_to_requested_addr(_requested_static_archive_bottom, static_archive_size);
my_archive_requested_bottom = align_up(_requested_static_archive_top, AOTMetaspace::core_region_alignment());
_requested_dynamic_archive_bottom = my_archive_requested_bottom;
@ -375,7 +375,7 @@ address ArchiveBuilder::reserve_buffer() {
_buffer_to_requested_delta = my_archive_requested_bottom - _buffer_bottom;
address my_archive_requested_top = my_archive_requested_bottom + buffer_size;
address my_archive_requested_top = ArchiveUtils::offset_to_requested_addr(my_archive_requested_bottom, buffer_size);
if (my_archive_requested_bottom < _requested_static_archive_bottom ||
my_archive_requested_top <= _requested_static_archive_bottom) {
// Size overflow.
@ -982,7 +982,7 @@ size_t ArchiveBuilder::any_to_offset(address p) const {
}
address ArchiveBuilder::offset_to_buffered_address(size_t offset) const {
address requested_addr = _requested_static_archive_bottom + offset;
address requested_addr = ArchiveUtils::offset_to_requested_addr(_requested_static_archive_bottom, offset);
address buffered_addr = requested_addr - _buffer_to_requested_delta;
assert(is_in_buffer_space(buffered_addr), "bad offset");
return buffered_addr;
@ -1048,7 +1048,7 @@ class RelocateBufferToRequested : public BitMapClosure {
address bottom = _builder->buffer_bottom();
address top = _builder->buffer_top();
address new_bottom = bottom + _buffer_to_requested_delta;
address new_bottom = ArchiveUtils::offset_to_requested_addr(bottom, _buffer_to_requested_delta);
address new_top = top + _buffer_to_requested_delta;
aot_log_debug(aot)("Relocating archive from [" INTPTR_FORMAT " - " INTPTR_FORMAT "] to "
"[" INTPTR_FORMAT " - " INTPTR_FORMAT "]",
@ -1109,7 +1109,7 @@ void ArchiveBuilder::relocate_to_requested() {
size_t my_archive_size = buffer_top() - buffer_bottom();
if (CDSConfig::is_dumping_static_archive()) {
_requested_static_archive_top = _requested_static_archive_bottom + my_archive_size;
_requested_static_archive_top = ArchiveUtils::offset_to_requested_addr(_requested_static_archive_bottom, my_archive_size);
RelocateBufferToRequested<true> patcher(this);
patcher.doit();
} else {

View File

@ -290,6 +290,12 @@ public:
static Array<T>* archive_array(GrowableArray<T>* tmp_array) {
return archive_ptr_array(tmp_array);
}
template <typename T>
static address offset_to_requested_addr(T requested_base, size_t offset) {
// As zero is allowed for requested_base, use integer arithmetic to avoid UB pointer arithmetic.
return (address)((uintptr_t)requested_base + offset);
}
};
class HeapRootSegments {