Repository navigation
Fix ILVerify crash on delegate construction - #135445
Merged
Merged
Conversation
When a delegate constructor's function pointer is a stack value that carries no method (for example a native int argument, local or constant rather than the result of ldftn/ldvirtftn), IsDelegateAssignable dereferenced the null method and threw NullReferenceException, which stopped verification of the rest of the assembly. StackMethod and DelegatePattern are already reported for that value, so skip the assignability check unless the value carries a method, and add a regression test.
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @agocke |
Member
|
/ba-g infrastructure timeout |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @dotnet/jit-contrib |
Contributor
Author
|
Thank you for the review and merge! |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Problem: when a delegate constructor's function pointer is a stack value that carries no method, such as a
native intargument, local or constant rather thanldftn/ldvirtftn, ILVerify throwsNullReferenceExceptioninIsDelegateAssignable. That stops the CLI from completing the assembly: later methods and the type pass are not verified. The repro is in the linked issue.Fix: skip the assignability check unless
actualFtn.IsMethod, mirroring theCheck(actualFtn.IsMethod, VerifierError.StackMethod)a few lines above.StackMethodhas already been reported for such a value, andCheckDelegateCreationreportsDelegatePattern. There is no target signature to compare, so the method fails with those two errors and verification continues.IsDelegateAssignablekeeps its non-null precondition, and its only caller is this path.Validation
New test in
FtnTests.il, alongside the otherNewObj.*cases:NewObj.DelegateFromNativeIntArgument_Invalid_StackMethod.DelegatePatternpassesldarg.0(anative int) as the function pointer.ILVerification.Tests, on
mainat dca76ff, with linux-x64 and SDK 11.0.100-rc.1.26420.103. Each row ran./dotnet.sh build src/coreclr/tools/ILVerification.Tests/ILVerification.Tests.csproj -c <config>, then the same command with/t:Test:mainunchangedNullReferenceExceptionThe rows for this change (Release, Debug, Checked) and the reverted-fix row were repeated on win-x64 from a fresh clone, with the same results.
ILVerifyCLI, built on linux-x64 from this branch and from its parent. The repro and the small assembly were run on linux-x64, osx-arm64 and win-x64; DotNext on linux-x64:NullReferenceException. After,StackMethodandDelegatePatternat offset 2, and the run completes.dup-prefixed variants of the crashing shape; aldftncarried across a branch; a plainldftndelegate; and later methods with aReturnVoiderror and aDelegateCtorsignature mismatch:StackMethod+DelegatePattern, and the branch caseDelegatePattern;ReturnVoidandDelegateCtorerrors are reported.lib/net8.0/DotNext.dll): before, it throws while verifying the 94th method. After, all 479 types and 3,429 methods are processed, with 368 errors reported.Corpus check (linux-x64). CLI output before and after this change, over 646 assemblies: Microsoft.NETCore.App 10.0.12 and 11.0.0-preview.7, Microsoft.AspNetCore.App 10.0.12, and 152 NuGet package assemblies. The only output that changed is
DotNext.dll, from the crash to a completed run.Scope
This changes only the
newobjdelegate path inImportCall, and adds the test.Resolves #135444
Note
This change and description were prepared with AI assistance (Anthropic Claude and OpenAI Codex), under my direction. I reviewed them before posting.