[release/10.0]: Avoid double free of STGMEDIUM while fetching stream data from clipboard#14296
[release/10.0]: Avoid double free of STGMEDIUM while fetching stream data from clipboard#14296Shyam-Gupta wants to merge 1 commit intorelease/10.0from
Conversation
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.
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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.
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 transferThe crash occurs inside
Clipboard.ContainsText(...)API when it is called in response toWM_CLIPBOARDUPDATEmessage. 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