Skip to content

Validate invalid base type declarations in ILVerify#129118

Open
pkuyo wants to merge 1 commit into
dotnet:mainfrom
pkuyo:fix-ilverify-119536
Open

Validate invalid base type declarations in ILVerify#129118
pkuyo wants to merge 1 commit into
dotnet:mainfrom
pkuyo:fix-ilverify-119536

Conversation

@pkuyo

@pkuyo pkuyo commented Jun 8, 2026

Copy link
Copy Markdown

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 InvalidBaseType for invalid base type declarations rather
than special-casing only the exact extends object spelling.

Tests added in BaseTypeTests.il:

  • ObjectTypeSpecBase_InvalidType_InvalidBaseType

    • Covers the original repro: a class declared with extends object.
    • Expected result: InvalidBaseType.
  • NilBaseInterface_ValidType_Valid

    • Ensures interfaces with no class base continue to verify successfully.
  • GenericClassTypeSpecBase_ValidType_Valid

    • Ensures valid generic class TypeSpec bases are still accepted.
  • ValueTypeBase_InvalidType_InvalidBaseType

    • Ensures a non-generic value type cannot be used as a class base.
  • GenericValueTypeSpecBase_InvalidType_InvalidBaseType

    • Ensures a generic value type instantiation cannot be used as a class base.

@github-actions github-actions Bot added the area-Tools-ILVerification Issues related to ilverify tool and IL verification in general label Jun 8, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jun 8, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @dotnet/jit-contrib
See info in area-owners.md if you want to be subscribed.

@pkuyo

pkuyo commented Jun 8, 2026

Copy link
Copy Markdown
Author

@dotnet-policy-service agree

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;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this any better than just calling _module.GetType(typeHandle)?

@pkuyo pkuyo Jun 8, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Tools-ILVerification Issues related to ilverify tool and IL verification in general community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ilverify fails to warn about invalid class declaration

2 participants