Skip to content

Commit

Permalink
Fix OOME handing in CreateAnnotationMember().
Browse files Browse the repository at this point in the history
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Change-Id: I63ba3eae20460156db9a8046f2fdbeb81419c4a0
  • Loading branch information
vmarko committed Nov 18, 2022
1 parent e00c97a commit b1baa73
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions runtime/dex/dex_file_annotations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -700,40 +700,53 @@ ObjPtr<mirror::Object> CreateAnnotationMember(const ClassData& klass,
StackHandleScope<5> hs(self);
uint32_t element_name_index = DecodeUnsignedLeb128(annotation);
const char* name = dex_file.StringDataByIdx(dex::StringIndex(element_name_index));
Handle<mirror::String> string_name(
hs.NewHandle(mirror::String::AllocFromModifiedUtf8(self, name)));

PointerSize pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
ArtMethod* annotation_method =
annotation_class->FindDeclaredVirtualMethodByName(name, pointer_size);
if (annotation_method == nullptr) {
return nullptr;
}
Handle<mirror::Class> method_return(hs.NewHandle(annotation_method->ResolveReturnType()));

Handle<mirror::String> string_name =
hs.NewHandle(mirror::String::AllocFromModifiedUtf8(self, name));
if (UNLIKELY(string_name == nullptr)) {
LOG(ERROR) << "Failed to allocate name for annotation member";
return nullptr;
}

Handle<mirror::Class> method_return = hs.NewHandle(annotation_method->ResolveReturnType());
if (UNLIKELY(method_return == nullptr)) {
LOG(ERROR) << "Failed to resolve method return type for annotation member";
return nullptr;
}

DexFile::AnnotationValue annotation_value;
if (!ProcessAnnotationValue<false>(klass,
annotation,
&annotation_value,
method_return,
DexFile::kAllObjects)) {
// TODO: Logging the error breaks run-test 005-annotations.
// LOG(ERROR) << "Failed to process annotation value for annotation member";
return nullptr;
}
Handle<mirror::Object> value_object(hs.NewHandle(annotation_value.value_.GetL()));
Handle<mirror::Object> value_object = hs.NewHandle(annotation_value.value_.GetL());

ArtMethod* annotation_member_init = WellKnownClasses::libcore_reflect_AnnotationMember_init;
ObjPtr<mirror::Class> annotation_member_class = annotation_member_init->GetDeclaringClass();
DCHECK(annotation_member_class->IsInitialized());
Handle<mirror::Object> new_member(hs.NewHandle(annotation_member_class->AllocObject(self)));
ObjPtr<mirror::Method> method_obj_ptr = (pointer_size == PointerSize::k64)
Handle<mirror::Method> method_object = hs.NewHandle((pointer_size == PointerSize::k64)
? mirror::Method::CreateFromArtMethod<PointerSize::k64>(self, annotation_method)
: mirror::Method::CreateFromArtMethod<PointerSize::k32>(self, annotation_method);
Handle<mirror::Method> method_object(hs.NewHandle(method_obj_ptr));
: mirror::Method::CreateFromArtMethod<PointerSize::k32>(self, annotation_method));
if (UNLIKELY(method_object == nullptr)) {
LOG(ERROR) << "Failed to create method object for annotation member";
return nullptr;
}

if (new_member == nullptr || string_name == nullptr ||
method_object == nullptr || method_return == nullptr) {
LOG(ERROR) << StringPrintf("Failed creating annotation element (m=%p n=%p a=%p r=%p",
new_member.Get(), string_name.Get(), method_object.Get(), method_return.Get());
ArtMethod* annotation_member_init = WellKnownClasses::libcore_reflect_AnnotationMember_init;
DCHECK(annotation_member_init->GetDeclaringClass()->IsInitialized());
Handle<mirror::Object> new_member =
hs.NewHandle(annotation_member_init->GetDeclaringClass()->AllocObject(self));
if (new_member == nullptr) {
LOG(ERROR) << "Failed to allocate annotation member";
return nullptr;
}

Expand Down

0 comments on commit b1baa73

Please sign in to comment.