[PR #16457] Fix conhost clipboard handling bugs #30923

Open
opened 2026-01-31 09:43:50 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/16457

State: closed
Merged: Yes


conhost has 2 bugs related to clipboard handling:

  • Missing retry on OpenClipboard: When copying to the clipboard
    explorer.exe is very eager to open the clipboard and peek into it.
    I'm not sure why it happens, but I can see CFSDropTarget in the
    call stack. It uses COM RPC and so this takes ~20ms every time.
    That breaks conhost's clipboard randomly during ConsoleBench.
    During non-benchmarks I expect this to break during RDP.
  • Missing null-terminator check during paste: CF_UNICODETEXT is
    documented to be a null-terminated string, which conhost v2
    failed to handle as it relied entirely on GlobalSize.

Additionally, this changeset simplifies the HGLOBAL code slightly
by adding _copyToClipboard to abstract it away.

Validation Steps Performed

  • ConsoleBench (#16453) doesn't fail randomly anymore
**Original Pull Request:** https://github.com/microsoft/terminal/pull/16457 **State:** closed **Merged:** Yes --- conhost has 2 bugs related to clipboard handling: * Missing retry on `OpenClipboard`: When copying to the clipboard explorer.exe is very eager to open the clipboard and peek into it. I'm not sure why it happens, but I can see `CFSDropTarget` in the call stack. It uses COM RPC and so this takes ~20ms every time. That breaks conhost's clipboard randomly during `ConsoleBench`. During non-benchmarks I expect this to break during RDP. * Missing null-terminator check during paste: `CF_UNICODETEXT` is documented to be a null-terminated string, which conhost v2 failed to handle as it relied entirely on `GlobalSize`. Additionally, this changeset simplifies the `HGLOBAL` code slightly by adding `_copyToClipboard` to abstract it away. ## Validation Steps Performed * `ConsoleBench` (#16453) doesn't fail randomly anymore ✅
claunia added the pull-request label 2026-01-31 09:43:50 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#30923