Skip to content

parser: bound datagram body allocation by message size - #343

Open
Mliviu79 wants to merge 1 commit into
emiago:mainfrom
Mliviu79:pr/parser-datagram-bound
Open

parser: bound datagram body allocation by message size#343
Mliviu79 wants to merge 1 commit into
emiago:mainfrom
Mliviu79:pr/parser-datagram-bound

Conversation

@Mliviu79

@Mliviu79 Mliviu79 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Fixes #342

One check, between the bodySize == 0 early return and the make:

if bodySize > p.MaxMessageLength-total {
    return msg, total, ErrMessageTooLarge
}

@emiago

emiago commented Aug 7, 2026

Copy link
Copy Markdown
Owner

pls remove comments. It is clear what is issue here. We solved this on streaming, not sure why I missed this.

The non-stream Parse path took the declared Content-Length straight into
make([]byte, bodySize) with only a negative-value guard. On a 64-bit build a
small unauthenticated datagram declaring a body of up to the uint32 maximum
(~4.29 GB) drove that allocation before the trailing copy could reject the
message: a pre-auth memory-amplification DoS on the UDP and WebSocket ingress
paths, both of which parse through ParseSIP -> Parse(stream=false). The stream
parser already bounds the body against MaxMessageLength; the datagram path now
does the same, subtracting rather than adding so the check itself cannot
overflow int on a 32-bit build.

Pre-existing, not introduced here (unrelated file transport_layer.go):
TestTransportLayerClientConnectionReuse and TestTransportLayerClientConnection
NoReuse fail under -race with data races in the client connection-reuse pool.
@Mliviu79
Mliviu79 force-pushed the pr/parser-datagram-bound branch from 3de3153 to 6a3cacc Compare August 9, 2026 10:29
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.

sip: Parser.Parse allocates the declared Content-Length before rejecting the message

2 participants