Skip to content

Cap payload allocations - #233

Open
gobwas wants to merge 2 commits into
masterfrom
fix/cap-allocs
Open

gobwas wants to merge 2 commits into
masterfrom
fix/cap-allocs

Conversation

@gobwas

@gobwas gobwas commented Oct 26, 2026

Copy link
Copy Markdown
Owner
ws,wsutil: do not trust peer-declared payload length for allocation

Payloads are now read through internal/saferio.ReadN(): at most 32 KiB
are allocated before the bytes actually arrive, the buffer grows with
them and ends with an exact capacity.

ws.ReadFrame() and MustReadFrame() are deprecated: the package has no
knob to bound a payload and none is in the RFC; it's now encouraged to
use ReadHeader() and check Header.Length instead.

wsutil.Reader gets MaxMessageSize, the total of all fragments (RFC 6455
section 10.4), which MaxFrameSize alone never bounded. The helpers are
configured with goroutine-safe SetMaxFrameSize(), SetMaxMessageSize(),
SetCheckUTF8() and SetPreallocLimit(), each with a getter, and
DefaultReader() returns the Reader they use. README and the package doc
recommend setting the limits.

Refs #223. Closes #229.

@gobwas
gobwas requested a review from cristaloleg October 26, 2026 06:38
@gobwas gobwas changed the title Fix/cap allocs Cap payload allocations Oct 26, 2026
Payloads are now read through internal/saferio.ReadN(): at most 32 KiB
are allocated before the bytes actually arrive, the buffer grows with
them and ends with an exact capacity.

ws.ReadFrame() and MustReadFrame() are deprecated: the package has no
knob to bound a payload and none is in the RFC; it's now encouraged to
use ReadHeader() and check Header.Length instead.

wsutil.Reader gets MaxMessageSize, the total of all fragments (RFC 6455
section 10.4), which MaxFrameSize alone never bounded. The helpers are
configured with goroutine-safe SetMaxFrameSize(), SetMaxMessageSize(),
SetCheckUTF8() and SetPreallocLimit(), each with a getter, and
DefaultReader() returns the Reader they use. README and the package doc
recommend setting the limits.

Refs #223. Closes #229.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant