Skip to content

Commit 29eae42

Browse files
[release/9.0-staging] [android] Fix crash in method_to_ir (#109510)
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 d31f394 commit 29eae42

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
@@ -5757,8 +5757,11 @@ check_get_virtual_method_assumptions (MonoClass* klass, MonoMethod* method)
57575757
* Returns null, if the optimization cannot be performed.
57585758
*/
57595759
static MonoMethod*
5760-
try_prepare_objaddr_callvirt_optimization (MonoCompile *cfg, guchar *next_ip, guchar* end, MonoMethod *method, MonoGenericContext* generic_context, MonoClass *klass)
5760+
try_prepare_objaddr_callvirt_optimization (MonoCompile *cfg, guchar *next_ip, guchar* end, MonoMethod *method, MonoGenericContext* generic_context, MonoType *param_type)
57615761
{
5762+
g_assert(param_type);
5763+
MonoClass *klass = mono_class_from_mono_type_internal (param_type);
5764+
57625765
// TODO: relax the _is_def requirement?
57635766
if (cfg->compile_aot || cfg->compile_llvm || !klass || !mono_class_is_def (klass))
57645767
return NULL;
@@ -7256,7 +7259,7 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
72567259
}
72577260
*sp++ = ins;
72587261
/*if (!m_method_is_icall (method)) */{
7259-
MonoMethod* callvirt_target = try_prepare_objaddr_callvirt_optimization (cfg, next_ip, end, method, generic_context, param_types [n]->data.klass);
7262+
MonoMethod* callvirt_target = try_prepare_objaddr_callvirt_optimization (cfg, next_ip, end, method, generic_context, param_types [n]);
72607263
if (callvirt_target)
72617264
cmethod_override = callvirt_target;
72627265
}

0 commit comments

Comments
 (0)