Skip to content

bounds-check OnUserControlMessage like sibling control handlers#3329

Open
sahvx655-wq wants to merge 1 commit into
apache:masterfrom
sahvx655-wq:ucm-min-length
Open

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

Conversation

@sahvx655-wq
Copy link
Copy Markdown

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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.

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) {
@wwbmmm
Copy link
Copy Markdown
Contributor

wwbmmm commented Jun 5, 2026

LGTM

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