8358289: [asan] runtime/cds/appcds/aotCode/AOTCodeFlags.java reports heap-buffer-overflow in ArchiveBuilder

Reviewed-by: shade, iklam, asmehra
This commit is contained in:
Vladimir Kozlov 2025-06-04 02:14:17 +00:00
parent 939521b8e4
commit ebd85288ce
2 changed files with 14 additions and 10 deletions

View File

@ -2199,10 +2199,11 @@ class AdapterFingerPrint : public MetaspaceObj {
} }
// Private construtor. Use allocate() to get an instance. // Private construtor. Use allocate() to get an instance.
AdapterFingerPrint(int total_args_passed, BasicType* sig_bt) { AdapterFingerPrint(int total_args_passed, BasicType* sig_bt, int len) {
int* data = data_pointer(); int* data = data_pointer();
// Pack the BasicTypes with 8 per int // Pack the BasicTypes with 8 per int
_length = length(total_args_passed); assert(len == length(total_args_passed), "sanity");
_length = len;
int sig_index = 0; int sig_index = 0;
for (int index = 0; index < _length; index++) { for (int index = 0; index < _length; index++) {
int value = 0; int value = 0;
@ -2217,16 +2218,15 @@ class AdapterFingerPrint : public MetaspaceObj {
// Call deallocate instead // Call deallocate instead
~AdapterFingerPrint() { ~AdapterFingerPrint() {
FreeHeap(this); ShouldNotCallThis();
} }
static int length(int total_args) { static int length(int total_args) {
return (total_args + (_basic_types_per_int-1)) / _basic_types_per_int; return (total_args + (_basic_types_per_int-1)) / _basic_types_per_int;
} }
static int compute_size(int total_args_passed, BasicType* sig_bt) { static int compute_size_in_words(int len) {
int len = length(total_args_passed); return (int)heap_word_size(sizeof(AdapterFingerPrint) + (len * sizeof(int)));
return sizeof(AdapterFingerPrint) + (len * sizeof(int));
} }
// Remap BasicTypes that are handled equivalently by the adapters. // Remap BasicTypes that are handled equivalently by the adapters.
@ -2289,12 +2289,15 @@ class AdapterFingerPrint : public MetaspaceObj {
public: public:
static AdapterFingerPrint* allocate(int total_args_passed, BasicType* sig_bt) { static AdapterFingerPrint* allocate(int total_args_passed, BasicType* sig_bt) {
int size_in_bytes = compute_size(total_args_passed, sig_bt); int len = length(total_args_passed);
return new (size_in_bytes) AdapterFingerPrint(total_args_passed, sig_bt); int size_in_bytes = BytesPerWord * compute_size_in_words(len);
AdapterFingerPrint* afp = new (size_in_bytes) AdapterFingerPrint(total_args_passed, sig_bt, len);
assert((afp->size() * BytesPerWord) == size_in_bytes, "should match");
return afp;
} }
static void deallocate(AdapterFingerPrint* fp) { static void deallocate(AdapterFingerPrint* fp) {
fp->~AdapterFingerPrint(); FreeHeap(fp);
} }
int value(int index) { int value(int index) {
@ -2418,7 +2421,7 @@ class AdapterFingerPrint : public MetaspaceObj {
// methods required by virtue of being a MetaspaceObj // methods required by virtue of being a MetaspaceObj
void metaspace_pointers_do(MetaspaceClosure* it) { return; /* nothing to do here */ } void metaspace_pointers_do(MetaspaceClosure* it) { return; /* nothing to do here */ }
int size() const { return (int)heap_word_size(sizeof(AdapterFingerPrint) + (_length * sizeof(int))); } int size() const { return compute_size_in_words(_length); }
MetaspaceObj::Type type() const { return AdapterFingerPrintType; } MetaspaceObj::Type type() const { return AdapterFingerPrintType; }
static bool equals(AdapterFingerPrint* const& fp1, AdapterFingerPrint* const& fp2) { static bool equals(AdapterFingerPrint* const& fp1, AdapterFingerPrint* const& fp2) {

View File

@ -711,6 +711,7 @@ class AdapterHandlerEntry : public MetaspaceObj {
// Dummy argument is used to avoid C++ warning about using // Dummy argument is used to avoid C++ warning about using
// deleted opearator MetaspaceObj::delete(). // deleted opearator MetaspaceObj::delete().
void* operator new(size_t size, size_t dummy) throw() { void* operator new(size_t size, size_t dummy) throw() {
assert(size == BytesPerWord * heap_word_size(sizeof(AdapterHandlerEntry)), "should match");
void* p = AllocateHeap(size, mtCode); void* p = AllocateHeap(size, mtCode);
memset(p, 0, size); memset(p, 0, size);
return p; return p;