Repository navigation
Validate invalid base type declarations in ILVerify #129118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
87dc394
Implement base type verification and add related tests
pkuyo 0657062
Add type specification validation and related tests
pkuyo a7ece37
Gate TypeSpec validation under ILVERIFICATION
pkuyo 828661d
Refine base type validation and update ILVerify expectations
pkuyo 74f03d2
Fix formatting in IL test files
pkuyo 60febc6
Avoid base type resolution in interface checks
pkuyo 6265b35
Validate TypeSpec parsing in EcmaSignatureParser
pkuyo e1ea8a3
Add ILVerify test for cyclic TypeSpec
pkuyo 7ddbf4b
Simplify cyclic TypeSpec ILVerify test
pkuyo 64d7e01
Reject TypeSpec custom modifiers
pkuyo 22f2d56
Fix TypeSpec parsing with modifiers
pkuyo 873f126
Updated Ecma-335-Augments.md
pkuyo fcba18c
Reformat TypeSpec custom modifier note
pkuyo 5210c29
Reject invalid top-level type codes in TypeSpec signatures
pkuyo 5fd0e41
Remove redundant TypeSpec base type check
pkuyo 6a6a92c
Remove extra blank line
pkuyo a0416ad
Initialize error arguments for BadTypeSpec verification results
pkuyo 21a8172
Update Ecma-335-Augments.md
pkuyo 69a8cf8
Improve BadTypeSpec verification diagnostics
pkuyo bcf96c9
Add ILVerify enum base type regression test
pkuyo fb71e6b
Merge branch 'main' into fix-ilverify-119536
jkotas 927ddb0
Clarify BadTypeSpec verification messages
pkuyo d1da679
Split TypeSpec verification error callbacks
pkuyo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
78 changes: 78 additions & 0 deletions
78
src/coreclr/tools/ILVerification.Tests/ILTests/BaseTypeTests.il
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| .assembly extern System.Runtime | ||
| { | ||
| } | ||
|
|
||
| .assembly BaseTypeTests | ||
| { | ||
| } | ||
|
|
||
| .class public auto ansi beforefieldinit ObjectTypeSpecBase_InvalidType_BadTypeSpec | ||
| extends object | ||
|
jkotas marked this conversation as resolved.
|
||
| { | ||
| .method public hidebysig specialname rtspecialname instance void .ctor() cil managed | ||
| { | ||
| .maxstack 8 | ||
|
|
||
| ldarg.0 | ||
| call instance void [System.Runtime]System.Object::.ctor() | ||
| ret | ||
| } | ||
| } | ||
|
|
||
| .class public auto ansi beforefieldinit ArrayTypeSpecBase_InvalidType_InvalidBaseType | ||
| extends int32[] | ||
| { | ||
| } | ||
|
|
||
| .class public auto ansi beforefieldinit PointerTypeSpecBase_InvalidType_InvalidBaseType | ||
| extends int32* | ||
| { | ||
| } | ||
|
|
||
| .class interface public auto ansi abstract NilBaseInterface_ValidType_Valid | ||
| { | ||
| } | ||
|
|
||
| .class public auto ansi beforefieldinit GenericBase`1<T> | ||
| extends [System.Runtime]System.Object | ||
| { | ||
| } | ||
|
|
||
| .class public auto ansi beforefieldinit GenericClassTypeSpecBase_ValidType_Valid | ||
| extends class GenericBase`1<int32> | ||
| { | ||
| } | ||
|
|
||
| .class public auto ansi beforefieldinit GenericOpenClassTypeSpecBase_ValidType_Valid`1<T> | ||
| extends class GenericBase`1<!0> | ||
| { | ||
| } | ||
|
|
||
| .class public sequential ansi sealed beforefieldinit ValueTypeBase | ||
| extends [System.Runtime]System.ValueType | ||
| { | ||
| } | ||
|
|
||
| .class public auto ansi beforefieldinit ValueTypeBase_InvalidType_InvalidBaseType | ||
| extends ValueTypeBase | ||
| { | ||
| } | ||
|
|
||
| .class public sequential ansi sealed beforefieldinit GenericValueTypeBase`1<T> | ||
| extends [System.Runtime]System.ValueType | ||
| { | ||
| } | ||
|
|
||
| .class public auto ansi sealed EnumBase_ValidType_Valid | ||
| extends [System.Runtime]System.Enum | ||
|
pkuyo marked this conversation as resolved.
|
||
| { | ||
| .field public specialname rtspecialname int32 value__ | ||
| } | ||
|
|
||
| .class public auto ansi beforefieldinit GenericValueTypeSpecBase_InvalidType_InvalidBaseType | ||
| extends valuetype GenericValueTypeBase`1<int32> | ||
| { | ||
| } | ||
9 changes: 9 additions & 0 deletions
9
src/coreclr/tools/ILVerification.Tests/ILTests/BaseTypeTests.ilproj
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.IL"> | ||
| <PropertyGroup> | ||
| <AssemblyName>$(MSBuildProjectName)</AssemblyName> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="$(MSBuildProjectName).il" /> | ||
| </ItemGroup> | ||
| </Project> |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -140,7 +140,7 @@ | |
|
|
||
| ldloca.s V_0 | ||
| ldstr "Hello" | ||
| stobj string | ||
| stobj [System.Runtime]System.String | ||
| ret | ||
| } | ||
|
|
||
|
|
||
30 changes: 30 additions & 0 deletions
30
src/coreclr/tools/ILVerification.Tests/ILTests/MalformedTypeSpecTests.il
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| .assembly extern System.Runtime | ||
| { | ||
| } | ||
|
|
||
| .assembly MalformedTypeSpecTests | ||
| { | ||
| } | ||
|
|
||
| .class public auto ansi beforefieldinit GenericBase`1<T> | ||
| extends [System.Runtime]System.Object | ||
| { | ||
| } | ||
|
|
||
| .class public auto ansi beforefieldinit CustomModifierTypeSpecBase_InvalidType_BadTypeSpec | ||
| extends class GenericBase`1<int32 modopt(int32)> | ||
| { | ||
| } | ||
|
|
||
| .class public auto ansi beforefieldinit MethodSignatureTests | ||
| extends [System.Runtime]System.Object | ||
| { | ||
| .method public static hidebysig int32 modopt(int32) CustomModifierTypeSpecReturn_Invalid_BadTypeSpec() cil managed | ||
| { | ||
| ldc.i4.0 | ||
| ret | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/coreclr/tools/ILVerification.Tests/ILTests/MalformedTypeSpecTests.ilproj
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.IL"> | ||
| <PropertyGroup> | ||
| <AssemblyName>$(MSBuildProjectName)</AssemblyName> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="$(MSBuildProjectName).il" /> | ||
| </ItemGroup> | ||
| </Project> |
26 changes: 26 additions & 0 deletions
26
src/coreclr/tools/ILVerification/EcmaSignatureParser.ILVerify.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Reflection.Metadata; | ||
| using System.Reflection.Metadata.Ecma335; | ||
| using ILVerify; | ||
| using Internal.IL; | ||
|
|
||
| namespace Internal.TypeSystem.Ecma | ||
| { | ||
| public partial struct EcmaSignatureParser | ||
| { | ||
| partial void ReportInvalidTypeSpecEncoding(EntityHandle typeSpecHandle) => | ||
| ThrowBadTypeSpec(typeSpecHandle, "The TypeSpec signature encoding is invalid."); | ||
|
|
||
| partial void ReportTypeSpecUsedAsCustomModifier(EntityHandle typeSpecHandle) => | ||
| ThrowBadTypeSpec(typeSpecHandle, "A TypeSpec token is not valid as a custom modifier type."); | ||
|
|
||
| private void ThrowBadTypeSpec(EntityHandle typeSpecHandle, string message) | ||
| { | ||
| throw new VerifierException( | ||
| VerifierError.BadTypeSpec, | ||
| $"{message} ([{_ecmaModule}]0x{MetadataTokens.GetToken(typeSpecHandle):X8})"); | ||
| } | ||
| } | ||
| } |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.