[mono] Avoid calling mono_metadata_type_hash () on the container class in mono_generi...
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Tue, 12 Jul 2022 17:55:23 +0000 (12:55 -0500)
committerGitHub <noreply@github.com>
Tue, 12 Jul 2022 17:55:23 +0000 (12:55 -0500)
If a class inherits from a generic instance instantiated with itself, then its possible
for mono_generic_class_hash () to be called while the container class is not fully
initialized yet, i.e. byval_arg.type is 0. This would cause the generic class to change
its hash.

Fixes https://github.com/dotnet/runtime/issues/71424.

Co-authored-by: Zoltan Varga <vargaz@gmail.com>
src/mono/mono/metadata/metadata.c

index 1e3cd55..c16b320 100644 (file)
@@ -1923,7 +1923,7 @@ static guint
 mono_generic_class_hash (gconstpointer data)
 {
        const MonoGenericClass *gclass = (const MonoGenericClass *) data;
-       guint hash = mono_metadata_type_hash (m_class_get_byval_arg (gclass->container_class));
+       guint hash = mono_metadata_str_hash (m_class_get_name (gclass->container_class));
 
        hash *= 13;
        hash += gclass->is_tb_open;