Avoid incorrectly resolving a MonoClass for MONO_TYPE_GENERICINST when loading custom attribute values.#123439
Merged
steveisok merged 10 commits intodotnet:mainfrom Apr 6, 2026
Merged
Conversation
Copilot AI
added a commit
that referenced
this pull request
Jan 21, 2026
Co-authored-by: lewing <24063+lewing@users.noreply.github.com>
This was referenced Jan 24, 2026
Open
Contributor
Author
|
@lewing should i add test cases to verify this? |
Member
lewing
approved these changes
Jan 31, 2026
This was referenced Jan 31, 2026
lewing
added a commit
to lewing/runtime
that referenced
this pull request
Feb 3, 2026
Change test from delegate*<void>[] to int[] to avoid hitting unrelated Mono function pointer type equality issue (dotnet#90308) while still testing the original crash fix (MONO_TYPE_GENERICINST handling in custom attribute decoding from PR dotnet#123439). Verified: - Test crashes on Mono WITHOUT the fix (m_type_data_get_klass error) - Test passes on Mono WITH the fix - Test passes on CoreCLR
lewing
added a commit
that referenced
this pull request
Feb 3, 2026
Add regression test for Mono crash when decoding custom attributes with generic enum arguments involving arrays (PR #123439). Uses GenericClassForEnum<int[]>.E to test the MONO_TYPE_GENERICINST handling in custom attribute decoding.
lewing
added a commit
that referenced
this pull request
Feb 3, 2026
Add regression test for Mono crash when decoding custom attributes with generic enum arguments involving arrays (PR #123439). Uses GenericClassForEnum<int[]>.E to test the MONO_TYPE_GENERICINST handling in custom attribute decoding. Co-authored-by: Michal Strehovsky <MichalStrehovsky@users.noreply.github.com>
Contributor
Author
|
Can we merge this? |
Contributor
|
@copilot |
Contributor
|
@lewing is the test case experimentation complete? can this be merged yet? |
This was referenced Feb 23, 2026
steveisok
approved these changes
Mar 3, 2026
Contributor
|
Can this be merged ? |
Member
|
/ba-g Generic known issues |
radekdoulik
pushed a commit
to radekdoulik/runtime
that referenced
this pull request
Apr 9, 2026
…n loading custom attribute values. (dotnet#123439) Avoid incorrectly resolving a MonoClass for `MONO_TYPE_GENERICINST` when loading custom attribute values. `load_cattr_value()` previously unconditionally called `m_type_data_get_klass()`, which is invalid for `GENERICINST` and could lead to incorrect behavior when processing generic enum instances. This change defers class resolution for `MONO_TYPE_GENERICINST` and handles enum generic instances explicitly by extracting the underlying element type. This fixes a crash when decoding custom attributes involving generic types. #### This crashes in Mono but doesn't in CoreClr ``` using System; using System.Collections; using System.Reflection; using System.Runtime.InteropServices; var attr = typeof(C).CustomAttributes.Single(d => d.AttributeType == typeof(A)); var arg = attr.ConstructorArguments.Single(); Console.WriteLine(arg.GetType()); class A : Attribute { public unsafe A(B<delegate*<void>[]>.E e) { } } class B<T> { public enum E { } } [A(default)] unsafe class C { } ``` #### Output on CoreClr: ``` System.Reflection.CustomAttributeTypedArgument ``` #### Output on Mono without fix: ``` MonoType with type 21 accessed by m_type_data_get_klass ================================================================= Native Crash Reporting ================================================================= Got a SIGABRT while executing native code. This usually indicates a fatal error in the mono runtime or one of the native libraries used by your application. ================================================================= ================================================================= Native stacktrace: ================================================================= 0x7fa2a25ffd2f - /home/venkad/dotnet10.0.100-mono/shared/Microsoft.NETCore.App/10.0.0-dev/libcoreclr.so : 0x7fa2a25a3e0e - /home/venkad/dotnet10.0.100-mono/shared/Microsoft.NETCore.App/10.0.0-dev/libcoreclr.so : 0x7fa2a25ff5b1 - /home/venkad/dotnet10.0.100-mono/shared/Microsoft.NETCore.App/10.0.0-dev/libcoreclr.so : 0x7fa2a2a29040 - /lib64/libc.so.6 : 0x7fa2a2a82e5c - /lib64/libc.so.6 : 0x7fa2a2a28f0e - /lib64/libc.so.6 : gsignal 0x7fa2a2a106d0 - /lib64/libc.so.6 : abort 0x7fa2a26ac244 - /home/venkad/dotnet10.0.100-mono/shared/Microsoft.NETCore.App/10.0.0-dev/libcoreclr.so : 0x7fa2a26b9e06 - /home/venkad/dotnet10.0.100-mono/shared/Microsoft.NETCore.App/10.0.0-dev/libcoreclr.so : 0x7fa2a26ac606 - /home/venkad/dotnet10.0.100-mono/shared/Microsoft.NETCore.App/10.0.0-dev/libcoreclr.so : 0x7fa2a26ac73e - /home/venkad/dotnet10.0.100-mono/shared/Microsoft.NETCore.App/10.0.0-dev/libcoreclr.so : 0x7fa2a277445b - /home/venkad/dotnet10.0.100-mono/shared/Microsoft.NETCore.App/10.0.0-dev/libcoreclr.so : 0x7fa2a277408d - /home/venkad/dotnet10.0.100-mono/shared/Microsoft.NETCore.App/10.0.0-dev/libcoreclr.so : 0x7fa2a276ee74 - /home/venkad/dotnet10.0.100-mono/shared/Microsoft.NETCore.App/10.0.0-dev/libcoreclr.so : 0x7fa2a276e9c4 - /home/venkad/dotnet10.0.100-mono/shared/Microsoft.NETCore.App/10.0.0-dev/libcoreclr.so : mono_reflection_create_custom_attr_data_args 0x7fa2a276fdbf - /home/venkad/dotnet10.0.100-mono/shared/Microsoft.NETCore.App/10.0.0-dev/libcoreclr.so : 0x7fa2a2704f08 - /home/venkad/dotnet10.0.100-mono/shared/Microsoft.NETCore.App/10.0.0-dev/libcoreclr.so : 0x4037366b - Unknown ``` #### Output on Mono with fix: ``` System.Reflection.CustomAttributeTypedArgument ``` Co-authored-by: Larry Ewing <lewing@microsoft.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Avoid incorrectly resolving a MonoClass for
MONO_TYPE_GENERICINSTwhen loading custom attribute values.load_cattr_value()previously unconditionally calledm_type_data_get_klass(), which is invalid forGENERICINSTand could lead to incorrect behavior when processing generic enum instances. This change defers class resolution forMONO_TYPE_GENERICINSTand handles enum generic instances explicitly by extracting the underlying element type. This fixes a crash when decoding custom attributes involving generic types.This crashes in Mono but doesn't in CoreClr
Output on CoreClr:
Output on Mono without fix:
Output on Mono with fix: