Skip to content

[Backport to release/10.0]: Clipboard.GetText(TextDataFormat.Rtf) does not retrieve RTF that lacks a null terminating character - #14527

Merged
SimonZhao888 merged 1 commit into
dotnet:release/10.0from
SimonZhao888:backport_fix_issue_14458
May 19, 2026
Merged

SimonZhao888 merged 1 commit into
dotnet:release/10.0from
SimonZhao888:backport_fix_issue_14458

Conversation

@SimonZhao888

@SimonZhao888 SimonZhao888 commented May 7, 2026 •

Copy link
Copy Markdown
Member

Backport #14461 to release/10.0

Fixes #14458

In ReadStringFromHGLOBAL method requires a null terminator to determine string length. The format dispatch switch groups RTF (a registered format) with CF_TEXT and CF_OEMTEXT (standard formats), routing RTF through this null-termination-required path.Composition.NativeToManagedAdapterReadStringFromHGLOBAL()

When external applications (PowerPoint, etc.) place RTF on the clipboard without a null terminator — which is valid per the Windows clipboard spec — the method returns instead of the actual RTF content.string.Empty

Proposed changes

  • Add a new method ReadRegisteredFormatStringFromHGLOBAL(HGLOBAL, Encoding) to handle the CF_RTF format without a null terminator.

Customer Impact

  • Clipboard.GetText(TextDataFormat.Rtf) can retrieve RTF that lacks a null terminating character.

Regression?

Risk

  • Minimal

Test methodology

  • Manual testing
  • Unit test
Microsoft Reviewers: Open in CodeFlow

… not retrieve RTF that lacks a null terminating character
@codecov

codecov Bot commented May 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.56522% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.10915%. Comparing base (e02e4db) to head (af1f6dd).
⚠️ Report is 6 commits behind head on release/10.0.

Additional details and impacted files
@@                  Coverage Diff                   @@
##           release/10.0      #14527         +/-   ##
======================================================
+ Coverage      77.10887%   77.10915%   +0.00028%     
======================================================
  Files              3273        3273                 
  Lines            645062      645083         +21     
  Branches          47704       47708          +4     
======================================================
+ Hits             497400      497418         +18     
- Misses           143986      143989          +3     
  Partials           3676        3676                 
Flag Coverage Δ
Debug 77.10915% <69.56522%> (+0.00028%) ⬆️
integration 18.98920% <0.00000%> (+0.00035%) ⬆️
production 51.93139% <69.56522%> (+0.00245%) ⬆️
test 97.40991% <ø> (ø)
unit 49.34416% <69.56522%> (-0.00013%) ⬇️

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.

@LeafShi1

LeafShi1 commented May 8, 2026

Copy link
Copy Markdown
Member

@SimonZhao888 For backport PRs, screenshots are not required, however, the "Test methodology," "Regression," and associated issues sections must be filled out in detail. Please refer to the PR #14121.

@KlausLoeffelmann KlausLoeffelmann 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.

Looks good to me - approved.
One thing, though:

We should add (as a follow-up PR, not in the context of this one) one additional test, where we test RTF with a terminator to establish, that the existing behavior really remains.

@SimonZhao888 SimonZhao888 added the servicing-approved .NET Shiproom approved the PR for merge label May 19, 2026
@SimonZhao888
SimonZhao888 merged commit 837b645 into dotnet:release/10.0 May 19, 2026
10 checks passed
@SimonZhao888
SimonZhao888 deleted the backport_fix_issue_14458 branch May 19, 2026 06:14
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

needs-area-label servicing-approved .NET Shiproom approved the PR for merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants