Skip to content

Fix PropVariant overwriting the next object on heap - #28186

Open
Martin Costello (martincostello) wants to merge 3 commits into
PowerShell:masterfrom
martincostello:fix-dotnet-runtime-131636
Open

Martin Costello (martincostello) wants to merge 3 commits into
PowerShell:masterfrom
martincostello:fix-dotnet-runtime-131636

Conversation

@martincostello

Copy link
Copy Markdown

PR Summary

PropVariant has 16 bytes of data but is passed to PropVariantClear as a 24 byte native PROPVARIANT, so clearing it zeroed the header of the next object on the heap. This caused intermittent runtime crashes on startup when that object was a COM object (dotnet/runtime#131636). Add a field so the managed object is large enough, and a test that fails without it.

PR Context

Fixes dotnet/runtime#131636.

PR Checklist

`PropVariant` has 16 bytes of data but is passed to `PropVariantClear` as a 24 byte native `PROPVARIANT`, so clearing it zeroed the header of the next object on the heap. This caused intermittent runtime crashes on startup when that object was a COM object (dotnet/runtime#131636). Add a field so the managed object is large enough, and a test that fails without it.

Assisted-by: Claude Code <noreply@anthropic.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@martincostello
Martin Costello (martincostello) marked this pull request as ready for review October 12, 2026 13:42
Copilot AI balanced review requested due to automatic review settings October 12, 2026 13:42

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

The layout correction addresses the root cause and is covered by a focused regression test.

0 open findings

What changed in this PR

Fixes heap corruption caused by undersized PropVariant interop layout.

Changes:

  • Adds native-layout padding to prevent overwriting adjacent objects.
  • Adds a Windows regression test for heap-header corruption.
File Description
src/​Microsoft.PowerShell.ConsoleHost/​WindowsTaskbarJumpList/​PropVariant.cs Makes the managed layout large enough for native clearing.
test/​xUnit/​csharp/​test_PropVariant.cs Verifies clearing does not corrupt an adjacent object.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Update the P/Invoke declaration to match the native API structure shapes explicitly.
Comment thread test/xUnit/csharp/test_PropVariant.cs Outdated
@iSazonov Ilya (iSazonov) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Oct 13, 2026
- Remove test.
- Fix build on macOS and Linux.
- Resolve CodeFactor suggestions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Intermittent "Internal CLR error. (0x80131506)" on Windows 11 ARM

4 participants