Skip to content

Commit 6d70f1b

Browse files
authored
Avoid an assert in ves_icall_RuntimeFieldInfo_SetValueInternal (#64214)
When the field is a valuetype and the value being assigned to the field is a reference type, throw an ArgumentException. Without this change the call to mono_object_handle_pin_unbox will assert and kill the process. This can occur when de-serializing an object and the field types have changed.
1 parent f531df6 commit 6d70f1b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/mono/mono/metadata/icall.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,8 +2065,16 @@ ves_icall_RuntimeFieldInfo_SetValueInternal (MonoReflectionFieldHandle field, Mo
20652065
case MONO_TYPE_VALUETYPE:
20662066
case MONO_TYPE_PTR:
20672067
isref = FALSE;
2068-
if (!MONO_HANDLE_IS_NULL (value))
2069-
v = (char*)mono_object_handle_pin_unbox (value, &value_gchandle);
2068+
if (!MONO_HANDLE_IS_NULL (value)) {
2069+
if (m_class_is_valuetype (mono_handle_class (value)))
2070+
v = (char*)mono_object_handle_pin_unbox (value, &value_gchandle);
2071+
else {
2072+
char* n = g_strdup_printf ("Object of type '%s' cannot be converted to type '%s'.", m_class_get_name (mono_handle_class (value)), m_class_get_name (mono_class_from_mono_type_internal (type)));
2073+
mono_error_set_argument (error, cf->name, n);
2074+
g_free (n);
2075+
return;
2076+
}
2077+
}
20702078
break;
20712079
case MONO_TYPE_STRING:
20722080
case MONO_TYPE_OBJECT:

0 commit comments

Comments
 (0)