Skip to content

fix null dereference in LoadConstraints for generic types - #136826

Merged
jkotas merged 2 commits into
dotnet:mainfrom
lagudafuadtosin:typevar-null-92566
Nov 3, 2026
Merged

jkotas merged 2 commits into
dotnet:mainfrom
lagudafuadtosin:typevar-null-92566

Conversation

@lagudafuadtosin

Copy link
Copy Markdown
Contributor

fixes #92566

pMT is only set for generic methods, so for a generic type both bad format throws in TypeVarTypeDesc::LoadConstraints dereferenced null. they now use the type's own token when pMT is null.

the new test gives a generic type a constraint pointing to a typespec token that does not exist. on main it segfaults, now it throws TypeLoadException. Loader/classloader regressions 115/115 and generics 217/217 pass.

pMT is only set for generic methods, so for a generic type both bad format throws in TypeVarTypeDesc::LoadConstraints dereferenced null. They now use the type's own token when pMT is null.

Fixes dotnet#92566
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Nov 2, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@jkotas

jkotas commented Nov 2, 2026

Copy link
Copy Markdown
Member

/azp run runtime-coreclr outerloop

@jkotas
jkotas requested a balanced review from Copilot November 2, 2026 23:36
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the null-dereference fix and accompanying malformed-metadata regression test.

No open issues 🎉

What changed in this PR

This PR addresses #92566 by preventing null dereferences in CoreCLR’s generic-type constraint loading when reporting malformed metadata.

Changes:

  • Use the type’s own token in both bad-format error paths when pMT is null.
  • Add an IL regression test expecting TypeLoadException for a nonexistent constraint TypeSpec token.
  • Configure the test for process isolation and exclude incompatible NativeAOT and IL round-trip runs.
File Description
src/​tests/​Loader/​classloader/​regressions/​GitHub_92566/​GitHub_92566.ilproj Configures the regression test and its compatibility exclusions.
src/​tests/​Loader/​classloader/​regressions/​GitHub_92566/​GitHub_92566.il Tests invalid constraint metadata produces TypeLoadException.
src/​coreclr/​vm/​typedesc.cpp Guards both error-reporting paths against a null pMT.

Review effort: Balanced

@jkotas jkotas left a comment

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.

Thanks

@jkotas

jkotas commented Nov 3, 2026

Copy link
Copy Markdown
Member

/ba-g known outer loop failures

@jkotas
jkotas merged commit 36797f3 into dotnet:main Nov 3, 2026
160 of 164 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-TypeSystem-coreclr 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.

Сhecking for NULL

3 participants