tsp-tcp: bound response size and handle short writes #4
Labels
No labels
nagonag
nagonag/ignore
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
heiko/mailseal#4
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
internal/tsp-tcp/tcp.gosends the request with oneconn.Writeand reads the response using unboundedio.ReadAll(conn).Risks:
net.Conn.Writeshould return a non-nil error for a short write, robust code must handlen != len(request)and returnio.ErrShortWriteeven if the error is nil.Writeitself reports an error.This endpoint is remote and untrusted. Context cancellation bounds time, but not allocation rate before the deadline.
Checklist: #81 (network-client timeout/resource hardening) and #53 (complete I/O error handling).
Proposed fix
max+1bytes usingio.LimitReader/LimitedReader; reject any response exceeding the maximum.n != len(request)withio.ErrShortWrite.Acceptance criteria
io.ErrShortWrite.Reviewed against
948b7a9onmaster(Go 1.26.2).Response-size bounds, exact-limit behavior, short-write handling, and regression coverage are complete.
Closing commit:
b5c194322a89