Skip to content

Fix issue 14458: Clipboard.GetText(TextDataFormat.Rtf) does not retrieve RTF that lacks a null terminating character#14461

Open
SimonZhao888 wants to merge 3 commits intodotnet:mainfrom
SimonZhao888:fix_issue_14458
Open

Fix issue 14458: Clipboard.GetText(TextDataFormat.Rtf) does not retrieve RTF that lacks a null terminating character#14461
SimonZhao888 wants to merge 3 commits intodotnet:mainfrom
SimonZhao888:fix_issue_14458

Conversation

@SimonZhao888
Copy link
Copy Markdown
Member

@SimonZhao888 SimonZhao888 commented Apr 10, 2026

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?

  • Yes

Risk

  • Minimal

Screenshots

Before

image

After

image

Test methodology

  • Manually

Test environment(s)

  • 11.0.100-preview.3.26170.106
Microsoft Reviewers: Open in CodeFlow

…eve RTF that lacks a null terminating character
@github-actions github-actions bot added the area-Clipboard Issues related to Clipboard label Apr 10, 2026
@dotnet-policy-service dotnet-policy-service bot added the draft draft PR label Apr 10, 2026
@SimonZhao888 SimonZhao888 marked this pull request as ready for review April 10, 2026 08:36
@SimonZhao888 SimonZhao888 requested a review from a team as a code owner April 10, 2026 08:36
@SimonZhao888 SimonZhao888 removed the draft draft PR label Apr 10, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes clipboard RTF retrieval when the “Rich Text Format” registered format payload is not null-terminated (valid per Win32 clipboard contract), by reading based on the HGLOBAL size instead of requiring a terminator.

Changes:

  • Route DataFormatNames.Rtf through a new size-based HGLOBAL string reader instead of the null-terminator-based path.
  • Add a unit test covering RTF payloads without a trailing null terminator.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/System.Private.Windows.Core/src/System/Private/Windows/Ole/Composition.NativeToManagedAdapter.cs Adds ReadRegisteredFormatStringFromHGLOBAL and updates the format dispatch so RTF is read via GlobalSize rather than terminator scanning.
src/System.Private.Windows.Core/tests/System.Private.Windows.Core.Tests/System/Private/Windows/Ole/NativeToManagedAdapterTests.cs Adds a regression test verifying RTF is returned even when the HGLOBAL buffer has no null terminator.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@SimonZhao888
Copy link
Copy Markdown
Member Author

Test Results for Bug 13929:
image

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clipboard.GetText(TextDataFormat.Rtf) does not retrieve RTF that lacks a null terminating character

2 participants