fix: bound frame payload allocations - #5
Conversation
kolkov
left a comment
There was a problem hiding this comment.
Addresses real unbounded-allocation vectors at three independent boundaries:
-
Transport read —
conn.godidmake([]byte, int(hdr.PayloadSize))from untrusted uint32 wire data. Now validates againstMaxPayloadSize(64 MiB) before conversion. 4K RGBA = ~31.6 MiB, so 64 MiB is a reasonable ceiling. -
LZ4 decode fallback — old code did
make([]byte, len(src)*10)without overflow protection, then doubled up to a fixed 64 MB. NewinitialDecodeSize/maxDecodeSizehelpers are overflow-safe and scale proportionally to input (maxDecodeRatio = 256), so a tiny malformed block can't force the full 64 MiB allocation. -
Server decompression —
decodePayloadallocatedmake([]byte, hdr.UncompressedSize)directly from the wire. Now validates againstMaxPayloadSizeand rejects compressed payloads with zero declared uncompressed size.
Good architectural decision: MaxPayloadSize in protocol as the single source of truth, header decode stays permissive (full uint32 range), limits enforced at allocation boundaries.
LGTM, merging.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
CI fails on all three PRs with the same config issue:
Could you drop the |
Summary
Why
Malformed or unsupported frame metadata should fail at the transport/decompression boundary rather than drive allocations from unchecked wire sizes. The codec also needs a proportional fallback ceiling so tiny invalid blocks cannot consume the full global budget.
Verification
go test -count=1 ./...go test -race -count=1 ./...go build ./...go vet ./...GOOS=linux GOARCH=386 go test -cfor changed protocol/codec/socket packagesgo test -coverprofile=coverage.out -covermode=atomic ./...: repository 94.6%; changed coverable statements 100%gofmtandgit diff --checkCurrent CI status
The upstream fork workflow for head
5e13b75is awaiting maintainer approval in Actions run 31433845350. Until that approval, GitHub cannot publish the repository's Actions or Codecov checks/comments. Local changed-line coverage is 100%.