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 Mar 11, 2026
Merged
Stream protocol: fix a crash in parse_command/1 on zero-size frames (backport #15703)#15709the-mikedavis merged 2 commits intov4.2.xfrom
parse_command/1 on zero-size frames (backport #15703)#15709the-mikedavis merged 2 commits intov4.2.xfrom
Conversation
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/1is called with an empty binary<<>>. No existing clause matches, causing afunction_clausecrash 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 validcommand()type and is handled gracefully by all three frame handlers inrabbit_stream_reader: pre-auth closes the connection, post-auth sends a protocol-level close frame withRESPONSE_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).