clipboard: QA log — verified against Windows source, PASS with 5 follow-up findings

Reviewed the diff against Core/Clipboard.cs, SocketStuff.cs, FormHelper.cs,
ReceivedDestinationFile.cs, Receiver.cs and Common.cs; ran tools/gates.sh
(all green). No wire-format, trust-gate, or logging violations found.
Findings are all low/medium severity and don't block CP2: the bulk
connection limit doesn't reproduce Windows's single-flight receive
semaphore, a dead stagingURL(in:) helper, a comment/behaviour mismatch
on the text-size gate, an unused AppKit import, and a send-time failure
message that can say "not found" instead of "too big" in a narrow race.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
lucioandClaude Sonnet 5 committed 2026-09-16 05:11:33 -07:00
1 parent 21963d54c9
commit e5e38b496e
1 file changed
+148
+148
View File
@@ -477,4 +477,152 @@ clipboard, no listener outside a few seconds on 127.0.0.1:51599):
## QA log
### 2026-09-16 — QA
Read `CLAUDE.md`, `docs/protocol.md` §2.3/§6/§10.7, `docs/contracts.md`
C1–C4 and this README end to end, then `git diff 18c9702..HEAD`. Ran
`tools/gates.sh` — all three gates green (`swift-format lint --strict`,
`MWBCore` layering, `swift build -Xswiftc -warnings-as-errors`). Built
only; nothing here touched the real pasteboard, opened a live listener
beyond what the codec/loopback harnesses in the work log already
exercised, launched the app, or wrote to `~/Desktop` (invariant 5).
**Per-tick verification against the Windows source**, reading
`Core/Clipboard.cs` whole, `Class/SocketStuff.cs:475-495, 1566-1931`,
`Helper/FormHelper.cs:180-330`, `Core/ReceivedDestinationFile.cs`,
`Core/Receiver.cs:273-380`, `Core/Event.cs:219-231` and
`Core/Common.cs:1291-1330`:
- Text/CF_HTML codec, 48-byte chunking, `Reassembler`'s duplicate-id
ring: traced against `Clipboard.cs:43-47, 190-201, 253-373,
1101-1194` and `Receiver.cs:40-82`. The ring's reasoning holds —
`SkSend` really does write one `Id` to both of a peer pair's control
connections, and `PreProcess` really does exempt `ClipboardText`/
`ClipboardImage` from the 50-entry ring (confirmed in
`Sources/MWBCore/Sequencing.swift:87-91`, unchanged by this lane) —
so keying by sending machine and de-duplicating by `Id` is the right
fix for the interleaving a socket-keyed loop never has to face.
- Bulk handshake: the raw, unframed 64-byte `DATA`, the bytes-1..3-zero
check (`BulkConnection.swift:230-241`), and the trust gate before any
payload (`BulkConnection.swift:258-276`) all match `Clipboard.cs:
961-1066`. Verified the less obvious half too: `ShakeHand` runs
identically on both ends, so the *connector* also authorises what it
reads back before it will send or receive — the port's `.pulling`/
`.pushing` roles go through the same `acceptHandshake`/`authorise`
path as `.accepted`, which is correct and not just incidental.
- 1024-byte header, error forms, 1 MB chunks, 32-byte padding: the
`trailingPadding` formula (`block - (length % block)`) matches
`SendFileEx`'s `PACKAGE_SIZE - (sentCount % PACKAGE_SIZE)`
(`SocketStuff.cs:1832-1836`) bit for bit, including the case the
formula name doesn't advertise — a body already block-aligned still
gets a full 32-byte pad, which is what Windows does too since the
`if (...> 0)` guard is never false for a `% PACKAGE_SIZE` computed
this way.
- `ReceivedFile` staging/commit/discard and path-traversal: `fileName
(fromHeaderName:)` strips both separators and refuses `.`/`..`
(`ClipboardCodec.swift:262-266`), and the staged file's random name is
independent of the attacker-controlled header name, so traversal
cannot reach outside the download folder.
- 100 MB limit and folder refusal, the 30 s window, pull-on-
`MachineSwitched` vs ask/push, pasteboard polling/quiet-period/
own-write suppression, `ShareClipboard`/`TransferFile` gating: each
traced to its `CheckClipboardEx` (`Clipboard.cs:85-251`) or
`Receiver.cs:273-380` counterpart and found correct, including the
easy-to-miss ones — `Clipboard (69)` really is un-addressed
(`ClipboardBridge.swift:190-195` applies no `Des` check, matching
`Receiver.cs:273-282`), and `MachineSwitched`/`ClipboardAsk` really
are gated on `Des == localID` (`:197-207`, matching `:284-291, 318`).
- The four `Engine.dispatch`/`EngineActions` call sites the dev added
beyond the brief: minimal and correct. Each is exactly the one line
the README's Handshakes section says it is, at the point app-engine
had already marked; `.machineSwitched` routing into
`clipboardDispatch` is right because Windows's own `MachineSwitched`
case in `Receiver.cs` does nothing *but* the clipboard-pull check —
there is no other received-side handling for that packet to
preserve.
- C1: `chunkPackets` returns unstamped packets; `forwardClipboardBatch`
stamps each once via the Engine's shared `stampAndForward` and hands
identical bytes to every target session (`ClipboardBridge.swift:
488-492`). No clipboard path re-stamps a forwarded packet.
- Invariant 2, checked end to end on the bulk connection: nothing is
read from `inbox` into `.header`/`.body` phase, and nothing is
written to a file or the pasteboard, before `authorised(true)`
returns from the Engine (`BulkConnection.swift:173-178, 258-276`).
- No clipboard content or the security key is logged anywhere in the
five changed files — checked every `Log.engine.*` and `fail(...)`
call site; all carry machine names, filenames, byte counts or fixed
strings, never payload bytes or `securityKey`.
**Findings** (none block CP2; see below).
1. `Sources/MWBNet/BulkChannel.swift:104-112` vs
`App/Core/Clipboard.cs:375, 925-941` and `App/Class/SocketStuff.cs:
1655-1665`. Windows serialises clipboard *receives* to exactly one
at a time, process-wide, with a real mutex
(`ClipboardReceiveGate = new SemaphoreSlim(1, 1)`): both the pull
path (`ReceiveAndProcessClipboardData` after dialling out) and the
accept-a-push path (`SendOrReceiveClipboardData`) wait on it, and a
second concurrent receive is rejected — socket closed, "Rejecting
clipboard transfer because the previous transfer is still active."
`BulkChannel.connectionLimit = 4` is not that: it caps *all* bulk
connections combined (both directions, any role) at four, so two
peers pushing to this Mac (or one pushing while another is pulled
from) can complete concurrently where Windows would drop the
second. The doc comment above `connectionLimit` calls this "the
equivalent bound" to the semaphore, which overstates it — it
neither serialises nor caps receives specifically. Failure scenario:
two of the three peers both copy a file within the same 30 s window
and both end up pulled/pushed to/from this Mac at once; both
transfers finish instead of one being rejected as Windows would
reject it. Not a wire-format or trust problem — each `BulkConnection`
is self-contained — but it is a silently un-ported behaviour and the
comment's citation doesn't hold up.
2. `Sources/MWBMac/ReceivedFile.swift:58-61` (`stagingURL(in:)`) is
dead: nothing calls it. `Sources/MWBNet/BulkConnection.swift:
336-339` has its own private `stagingURL()` instead, for the
layering reason the README's "Five deviations" section gives — a
good reason, but it leaves the `ReceivedFile` copy, which the
README's "Promised" interface still lists as public API, unused by
anything in `Sources` or `Tests`.
3. `Sources/MWBMac/Pasteboard.swift:123-126`. The comment says the
20 MB gate is "measured on the tagged blob before compression"
citing `FormHelper.cs:204-210`, but the code sums
`text.plain?.count + text.rtf?.count + text.html?.count` — the
three flavour strings alone, without the `"TXT"`/`"RTF"`/`"HTM"`
tags or the ~38-character `SEP` GUID appended after each one
Windows includes in `st.Length`. The undercount is at most a few
hundred characters against a 20,000,000-character limit, so no
realistic copy crosses it one way and not the other, but the
comment claims more fidelity to `FormHelper.cs` than the code has.
4. `Sources/mwb/ClipboardBridge.swift:17`. `import AppKit` is unused —
no `NS`/`CG` symbol appears anywhere in the file; every AppKit
access already goes through `MWBMac` as the file's own header
comment says it should.
5. `Sources/MWBNet/BulkConnection.swift:397-409` vs
`Sources/mwb/ClipboardBridge.swift:143-160`. `localFile` decides
"too big" vs "not found" once, at copy time. `beginSending`
independently re-derives the file's size at send time and, on any
failure there (deleted **or** grown past 100 MB since the copy),
always reports `"<path> not found!"` — never `"<path> - File too
big..."`, which Windows's own send path preserves by re-testing the
cached message string rather than the file (`SocketStuff.cs:
1690-1697`). Cosmetic only (still a well-formed `"0*…"` failure) and
the window is narrow — a file would have to cross 100 MB in the 30 s
between copy and a peer's pull — but it is a case Windows's message
distinguishes and the port's doesn't.
No fixes applied — none of the above is a typo or a trivially wrong
comment; findings 3 and 4 are the closest, but 3 is a behavioural
question (what should the gate measure?) for the dev/lead to answer
rather than a QA judgment call, and 4 is a one-line deletion that is
still the dev's to make since it's their file.
Everything else — the four Engine call sites, the offer-clearing and
size-cap fixes, the pacing, the padding formula, the CF_HTML wrap/
unwrap, the reassembler ring, the trust gate, the destination folder
and its atomic commit — checked out against the Windows source with no
further findings.
Verdict: PASS
## Review