Validate invalid base type declarations in ILVerify#129118
Open
pkuyo wants to merge 1 commit into
Open
Conversation
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @dotnet/jit-contrib |
Author
|
@dotnet-policy-service agree |
jkotas
reviewed
Jun 8, 2026
Comment on lines
+81
to
+100
| TypeSpecification typeSpecification = _module.MetadataReader.GetTypeSpecification(typeSpecificationHandle); | ||
| BlobReader signatureReader = _module.MetadataReader.GetBlobReader(typeSpecification.Signature); | ||
|
|
||
| if (signatureReader.ReadSignatureTypeCode() != SignatureTypeCode.GenericTypeInstance) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| int genericTypeKind = signatureReader.ReadCompressedInteger(); | ||
| if (genericTypeKind != (int)SignatureTypeKind.Class) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| EntityHandle genericTypeHandle = signatureReader.ReadTypeHandle(); | ||
| if (genericTypeHandle.Kind != HandleKind.TypeDefinition && | ||
| genericTypeHandle.Kind != HandleKind.TypeReference) | ||
| { | ||
| return false; | ||
| } |
Member
There was a problem hiding this comment.
Is this any better than just calling _module.GetType(typeHandle)?
Author
There was a problem hiding this comment.
I tried that locally again, using only _module.GetType(typeHandle) does not catch the #119536 repro. (ObjectTypeSpecBase_InvalidType_InvalidBaseType)
In the extends object case, _module.GetType(typeHandle) resolves the TypeSpec to System.Object, which loses the issue that the base type was encoded as an invalid TypeSpec in the extends clause.
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.
Fixes #119536
This adds ILVerify validation for invalid class base type declarations.
The original issue reports a case where ILAsm accepts a type declared with
extends object, but the resulting type cannot be loaded by the runtime.ILVerify previously accepted that assembly without reporting an error.
This change reports
InvalidBaseTypefor invalid base type declarations ratherthan special-casing only the exact
extends objectspelling.Tests added in
BaseTypeTests.il:ObjectTypeSpecBase_InvalidType_InvalidBaseTypeextends object.InvalidBaseType.NilBaseInterface_ValidType_ValidGenericClassTypeSpecBase_ValidType_ValidValueTypeBase_InvalidType_InvalidBaseTypeGenericValueTypeSpecBase_InvalidType_InvalidBaseType