Skip to content

[release/10.0]: Avoid double free of STGMEDIUM while fetching stream data from clipboard#14296

Open
Shyam-Gupta wants to merge 1 commit intorelease/10.0from
dev/shgu/bug11401_10.0
Open

[release/10.0]: Avoid double free of STGMEDIUM while fetching stream data from clipboard#14296
Shyam-Gupta wants to merge 1 commit intorelease/10.0from
dev/shgu/bug11401_10.0

Conversation

@Shyam-Gupta
Copy link
Member

@Shyam-Gupta Shyam-Gupta commented Feb 13, 2026

Fixes #14308

Description/Customer Impact: In WPF GitHub repo, a customer reported that after upgrading to .NET 10, a WPF application intermittently crashes with an unhandled native CFG violation exception: Indirect call guard check detected invalid control transfer

The crash occurs inside Clipboard.ContainsText(...) API when it is called in response to WM_CLIPBOARDUPDATE message. The same code path worked reliably in previous .NET versions.

Regression: Since .NET 9, WinForms and WPF have started using shared Clipboard code which is owned by WinForms. This change modified the clipboard logic substantially for both the UI stacks as compared to .NET 8 and previous versions.

Risk of this change: Low. The change only avoids using ComScope which was double freeing the memory pointer. In all other places in the code, ComScope is not in use for STGMEDIUM. So there is prior art for this fix.
Although we couldn't repro the issue internally, CTI team did extensive internal testing with the changes in this PR and didn't find any new issue.

Issue: #14308

main branch commit: #14257

Root cause: Due to use of ComScope , the STGMEDIUM was getting released twice - once by ComScope and once in the finally block. It was causing intermittent CFG exception.

Fix: Don't use ComScope in this case.

Note: We checked other use cases of STGMEDIUM in the repo and confirmed that ComScope is not being used for them.

Microsoft Reviewers: Open in CodeFlow

Issue: Due to use of ComScope , the STGMEDIUM was getting released twice - once by ComScope and once in the finally block. It was causing intermittent CFG exception.

Fix: Don't use ComScope in this case.

Note: We checked other use cases of STGMEDIUM in the repo and confirmed that ComScope is not being used for them.
@Shyam-Gupta
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@codecov
Copy link

codecov bot commented Feb 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.11109%. Comparing base (bf93aff) to head (69e1357).
⚠️ Report is 5 commits behind head on release/10.0.

Additional details and impacted files
@@                  Coverage Diff                   @@
##           release/10.0      #14296         +/-   ##
======================================================
+ Coverage      77.10582%   77.11109%   +0.00527%     
======================================================
  Files              3273        3273                 
  Lines            645033      645033                 
  Branches          47701       47701                 
======================================================
+ Hits             497358      497392         +34     
+ Misses           144000      143968         -32     
+ Partials           3675        3673          -2     
Flag Coverage Δ
Debug 77.11109% <100.00000%> (+0.00527%) ⬆️
integration 18.99024% <0.00000%> (-0.00069%) ⬇️
production 51.93587% <100.00000%> (+0.01180%) ⬆️
test 97.40998% <ø> (ø)
unit 49.35262% <100.00000%> (+0.01632%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Shyam-Gupta Shyam-Gupta marked this pull request as ready for review February 20, 2026 18:59
@Shyam-Gupta Shyam-Gupta requested a review from a team as a code owner February 20, 2026 18:59
@dotnet-policy-service dotnet-policy-service bot removed the draft draft PR label Feb 20, 2026
@Shyam-Gupta Shyam-Gupta added this to the .NET 10.0 milestone Feb 20, 2026
@mcastro-x mcastro-x added the servicing-consider .NET Shiproom label indicating a PR seeks to enter into a branch under Tell-Mode criteria label Feb 20, 2026
Copy link
Member

@KlausLoeffelmann KlausLoeffelmann left a comment

Choose a reason for hiding this comment

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

Looks the right thing to do here, and thank you for the bug fix!

Just for the record, @merriemcgaw:
This shared clipboard concept seems to me as a high risk, since what surfaces as bugs in WPF needs to be fixed AND effects WinForms.

That these are not always identical and comparatively difficult to debug, the list of bugs we already had here, clearly shows.

The suggestions made by Copilot I mentioned the other day, seem to be more warranted than I thought.

Let's see, that we get the documentation updates in as quickly as possible, if that's OK with you.

@Shyam-Gupta, thanks for taking that on so quickly, and thanks for being able, to come up with a solution for that in the time being.

@Shyam-Gupta Shyam-Gupta changed the title Avoid double free of STGMEDIUM while fetching stream data from clipboard [release/10.0]: Avoid double free of STGMEDIUM while fetching stream data from clipboard Feb 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Clipboard Issues related to Clipboard servicing-consider .NET Shiproom label indicating a PR seeks to enter into a branch under Tell-Mode criteria

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression in .NET 10: CFG violation (Indirect call guard check) when accessing Clipboard

3 participants