diff options
author | github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> | 2022-02-02 14:57:32 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-02 14:57:32 +0300 |
commit | a6f3e8f179abb1b3c6f5b5a86500b3837cd9eeb4 (patch) | |
tree | b1d7e8a039e4bac1913c3118f6346c7dc12b502e | |
parent | 3c4f3de377ded54b48f5b6b23b4e380be3aa21da (diff) |
Avoid an assert in ves_icall_RuntimeFieldInfo_SetValueInternal (#21420)mono-6.12.0.168
When the field is byref but the value being passes in is not, 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.
Co-authored-by: bholmes <bholmes@users.noreply.github.com>
-rw-r--r-- | mono/metadata/icall.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/mono/metadata/icall.c b/mono/metadata/icall.c index b7e13713cd4..6d16b9c3540 100644 --- a/mono/metadata/icall.c +++ b/mono/metadata/icall.c @@ -2486,8 +2486,16 @@ ves_icall_RuntimeFieldInfo_SetValueInternal (MonoReflectionFieldHandle field, Mo case MONO_TYPE_VALUETYPE: case MONO_TYPE_PTR: isref = FALSE; - if (!MONO_HANDLE_IS_NULL (value)) - v = (char*)mono_object_handle_pin_unbox (value, &value_gchandle); + if (!MONO_HANDLE_IS_NULL (value)) { + if (m_class_is_valuetype (mono_handle_class (value))) + v = (char*)mono_object_handle_pin_unbox (value, &value_gchandle); + else { + 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))); + mono_error_set_argument (error, cf->name, n); + g_free (n); + return; + } + } break; case MONO_TYPE_STRING: case MONO_TYPE_OBJECT: |