clipboard: de-duplicate in-band chunks by Id

A machine pair keeps two control connections and PreProcess exempts
ClipboardText/ClipboardImage from the replay ring (Receiver.cs:40-82), so
every chunk is delivered twice. Windows reassembles from the one socket the
first chunk arrived on (Clipboard.cs:308-373) and never sees it; ours is
keyed by sending machine, so the copies interleaved and corrupted the
payload. Reassembler now keeps a 50-entry ring of chunk Ids, which works
because contracts C1 stamps one Id per chunk for both deliveries.
docs/protocol.md §10.7 note 11.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
lucioandClaude Opus 5 committed 2026-09-16 04:56:31 -07:00
1 parent 105a34cb45
commit dd26befe58
3 files changed
+59 -5

No files matched your search

+17
View File
@@ -1051,3 +1051,20 @@ sees them. One subsection per lane, appended, never rewritten.
24 000 packets of it. The helper refuses to read text over 20 MB or an
image over 50 MB off the clipboard in the first place
(`FormHelper.cs:28-29, 206, 287`).
11. **Every in-band clipboard chunk is delivered twice, and only the Windows
receive loop's shape hides it.** A machine pair keeps two control
connections (§10.3 note 4) and `SkSend` writes the same bytes with the same
`Id` to both (§10.2 note 11), while `Receiver.PreProcess` exempts
`ClipboardText` and `ClipboardImage` from the 50-entry replay ring
(`Receiver.cs:40-82`). On Windows the first chunk to arrive hands its
*socket* to `ReceiveClipboardDataUsingTCP`, which then reads the rest of the
transfer from that socket alone (`Clipboard.cs:308-373`) — so the second
copy becomes a separate, parallel reassembly on the other socket's thread
and ends as a second, identical clipboard write. A port whose reassembly is
keyed by *sending machine* rather than by socket instead sees the two copies
interleave into one buffer and corrupt it. `Reassembler` therefore keeps its
own 50-entry ring of chunk `Id`s — which works precisely because contracts
C1 stamps one `Id` per chunk for both deliveries. `ClipboardDataEnd (76)` is
**not** exempt from the replay ring, so exactly one terminator arrives; a
copy that arrives wholly after the terminator starts a reassembly that can
never finish and is dropped by the idle timeout.