Skip to content

bounds-check OnUserControlMessage like sibling control handlers#3329

Open
sahvx655-wq wants to merge 2 commits into
apache:masterfrom
sahvx655-wq:ucm-min-length
Open

bounds-check OnUserControlMessage like sibling control handlers#3329
sahvx655-wq wants to merge 2 commits into
apache:masterfrom
sahvx655-wq:ucm-min-length

Conversation

@sahvx655-wq

Copy link
Copy Markdown
Contributor

the sibling control-message handlers (OnSetChunkSize, OnAck, OnWindowAckSize, OnSetPeerBandwidth) all validate message_length before touching the body, but OnUserControlMessage only caps the upper bound at 32. reading the code, a user control message with length 0 or 1 reads the 2-byte event type past the end of the stack buffer, and message_length - 2 underflows (uint32_t) to roughly 4G for the event_data StringPiece. require at least 2 bytes up front like the siblings do.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens RTMP control-message parsing by adding a lower-bound length check to RtmpChunkStream::OnUserControlMessage, aligning it with sibling control handlers and preventing out-of-bounds reads / unsigned underflow when the message body is shorter than the 2-byte event type.

Changes:

  • Reject user control messages with message_length < 2 (and keep the existing upper bound of 32).
  • Improve the error log to report the invalid length value.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/brpc/policy/rtmp_protocol.cpp Outdated
const RtmpMessageHeader& mh, butil::IOBuf* msg_body, Socket* socket) {
if (mh.message_length > 32) {
RTMP_ERROR(socket, mh) << "No user control message long as "
if (mh.message_length < 2 || mh.message_length > 32) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Pushed making both bounds 2u/32u so they line up with the != 4u / != 5u siblings and the uint32_t message_length. No behaviour change, just removes the signed/unsigned mismatch on the comparison.

@wwbmmm

wwbmmm commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

LGTM

@sahvx655-wq

Copy link
Copy Markdown
Contributor Author

Only change since your LGTM is the 2u/32u literal tidy-up the bot flagged, so the bounds match the != 4u / != 5u siblings in the same file. The guard logic is unchanged.

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