Skip to content

Stream protocol: fix a crash in parse_command/1 on zero-size frames (backport #15703)#15709

Merged
the-mikedavis merged 2 commits intov4.2.xfrom
mergify/bp/v4.2.x/pr-15703
Mar 11, 2026
Merged

Stream protocol: fix a crash in parse_command/1 on zero-size frames (backport #15703)#15709
the-mikedavis merged 2 commits intov4.2.xfrom
mergify/bp/v4.2.x/pr-15703

Conversation

@mergify
Copy link
Copy Markdown

@mergify mergify bot commented Mar 11, 2026

When a client sends a zero-size frame — for example, a port scanner sending <<0,0,0,0,0,0,0,0>> to the TLS-enabled stream listeners port, parse_command/1 is called with an empty binary <<>>. No existing clause matches, causing a function_clause crash that terminates the stream connection process. This has been observed consistently on EC2-hosted brokers.

Add a catch-all clause that returns {unknown, Data} for any binary that is not a valid request or response frame. {unknown, binary()} is already a valid command() type and is handled gracefully by all three frame handlers in rabbit_stream_reader: pre-auth closes the connection, post-auth sends a protocol-level close frame with RESPONSE_CODE_UNKNOWN_FRAME, and post-close ignores it.

The fix is accompanied by a test that reproduces the exact crash using the 8-byte payload observed in production logs.


This is an automatic backport of pull request #15703 done by [Mergify](https://mergify.com).

A zero-size frame (a 4-byte header with value 0) causes
`parse_command/1` to be called with an empty binary `<<>>`, for which
no clause matches, crashing the stream connection process.

Add a test case that reproduces the crash by sending the exact 8-byte
payload observed in production logs from EC2-hosted brokers.

(cherry picked from commit 2453561)
When a client sends a zero-size frame (e.g. a port scanner sending
`<<0,0,0,0,0,0,0,0>>`), `parse_command/1` is called with an empty
binary `<<>>`. No existing clause matches, causing a `function_clause`
crash that terminates the stream connection process.

Add a catch-all clause that returns `{unknown, Data}` for any binary
that is not a valid request or response frame. This is already a valid
`command()` type and is handled gracefully by all three frame handlers
in `rabbit_stream_reader`: pre-auth closes the connection, post-auth
sends a protocol-level close frame, and post-close ignores it.

(cherry picked from commit 3510476)
@michaelklishin michaelklishin added this to the 4.2.5 milestone Mar 11, 2026
@the-mikedavis the-mikedavis merged commit bd6b6a5 into v4.2.x Mar 11, 2026
293 checks passed
@the-mikedavis the-mikedavis deleted the mergify/bp/v4.2.x/pr-15703 branch March 11, 2026 22:10
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.

3 participants