Skip to content

Commit c489a8c

Browse files
[release/8.0-staging] [android] Fix crash in method_to_ir (#109511)
Backport of #109381 There exists a possibility where the klass being passed to try_prepare_objaddr_callvirt_optimization is not legit. This can result in unpredictable crashes. To fix, we pass the MonoType and flush out the MonoClass by calling mono_class_from_mono_type_internal. Fixes #109111
1 parent 77fba2f commit c489a8c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/mono/mono/mini/method-to-ir.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5703,8 +5703,11 @@ check_get_virtual_method_assumptions (MonoClass* klass, MonoMethod* method)
57035703
* Returns null, if the optimization cannot be performed.
57045704
*/
57055705
static MonoMethod*
5706-
try_prepare_objaddr_callvirt_optimization (MonoCompile *cfg, guchar *next_ip, guchar* end, MonoMethod *method, MonoGenericContext* generic_context, MonoClass *klass)
5706+
try_prepare_objaddr_callvirt_optimization (MonoCompile *cfg, guchar *next_ip, guchar* end, MonoMethod *method, MonoGenericContext* generic_context, MonoType *param_type)
57075707
{
5708+
g_assert(param_type);
5709+
MonoClass *klass = mono_class_from_mono_type_internal (param_type);
5710+
57085711
// TODO: relax the _is_def requirement?
57095712
if (cfg->compile_aot || cfg->compile_llvm || !klass || !mono_class_is_def (klass))
57105713
return NULL;
@@ -7129,7 +7132,7 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
71297132
}
71307133
*sp++ = ins;
71317134
/*if (!m_method_is_icall (method)) */{
7132-
MonoMethod* callvirt_target = try_prepare_objaddr_callvirt_optimization (cfg, next_ip, end, method, generic_context, param_types [n]->data.klass);
7135+
MonoMethod* callvirt_target = try_prepare_objaddr_callvirt_optimization (cfg, next_ip, end, method, generic_context, param_types [n]);
71337136
if (callvirt_target)
71347137
cmethod_override = callvirt_target;
71357138
}

0 commit comments

Comments
 (0)