session-matrix: a failed read spends the untrusted budget, as on Windows
QA finding 1. TcpReceiveData does not signal a bad read out of band: it rewrites the buffer's type byte to PackageType.Error (0 bytes) or PackageType.Invalid (short read) (SocketStuff.cs:574-578, 588-593) and MainTCPRoutine runs that package through the whole loop body — the private errCount for the Error case (:1332-1364), then the same untrusted counting as any garbage packet (:1370-1529). So a run of malformed reads ends in .invalidKey, not .error, and the trusted branch's `receivedCount > 0` guard (:1531) keeps a 0-byte read out of the receiver. Session.noteReceiveError now takes the byte count and feeds a synthetic .error/.invalid packet through the new receive(_:bytesReceived:), which is the loop body; feed() goes through it too. Written up as protocol §10.2 note 10 and in the README's Assumptions. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
1 parent
08b243a29a
commit
0e6ee77dc7
3 files changed
+73
-15
No files matched your search
@@ -38,6 +38,14 @@ the Windows source again.
|
||||
10 the session reports `.invalidKey` and asks to close
|
||||
(`SocketStuff.cs:1387-1406`). Application packets are surfaced to the
|
||||
caller only from a trusted session (CLAUDE.md invariant 2).
|
||||
- **A failed read is a packet.** Windows builds a `PackageType.Error`
|
||||
(0 bytes read) or `PackageType.Invalid` (short read) package out of the
|
||||
read itself (`SocketStuff.cs:574-578, 588-593`) and runs it through the
|
||||
whole loop body, so a malformed read spends the same untrusted budget
|
||||
as a garbage packet; only the 0-byte kind also feeds the
|
||||
six-in-a-row close (`:1330-1364`). The caller therefore passes the byte
|
||||
count — `noteReceiveError(bytesReceived:)` — and must not translate a
|
||||
short read into a 0-byte one (docs/protocol.md §10.2 note 10).
|
||||
- **Sequence numbers and the replay ring are process-wide**, as on
|
||||
Windows (`Common.cs:906`, `Receiver.cs:40-82`): a `PacketSequencer`
|
||||
and a `ReplayFilter` are created once by the app and shared by every
|
||||
@@ -149,7 +157,7 @@ public final class Session { // not Sendable: one per connecti
|
||||
public init(config:sequencer:replay:isClient:)
|
||||
public func start(now: TimeInterval) // queues 10 Handshake packets
|
||||
public func feed(_ plaintext: Data) // 32-then-32 reassembly inside
|
||||
public func noteReceiveError() // a 0-byte / short read
|
||||
public func noteReceiveError(bytesReceived: Int) // a 0-byte / short read
|
||||
public func report(_ new: SocketStatus) // .resolving, .sendError, …
|
||||
public func tick(now: TimeInterval, userActive: Bool)
|
||||
public func send(_ packet: Packet) // stamps Id + Src, frames, queues
|
||||
|
||||
Reference in new issue
Block a user