Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
An active moderate finding remains because incomplete RTMP-looking input can pin protocol selection and indefinitely block valid non-RTMP requests.
1 open issue
What changed in this PR
This PR improves RTMP protocol detection on shared ports by validating handshake data before claiming a connection, while preserving support for simplified, simple, and complex handshakes.
Changes:
- Requires complete C0+C1 data and validates supported C1 version fields before selecting RTMP.
- Preserves five-byte
03BDMSsimplified-handshake detection. - Adds tests for ambiguous payloads, fragmented handshakes, and simple/complex handshake acceptance.
| File | Description |
|---|---|
| test/brpc_rtmp_unittest.cpp | Expands RTMP parser tests for handshake validation, protocol fallback, fragmentation, and simple/complex handshake acceptance. |
| src/brpc/policy/rtmp_protocol.cpp | Implements C1-aware RTMP sniffing while retaining simplified-handshake detection. |
Review effort: Lite
Comment on lines
+3487
to
3488
| if (len < RTMP_HANDSHAKE_SIZE0 + RTMP_HANDSHAKE_SIZE1) { | ||
| return MakeParseError(PARSE_ERROR_NOT_ENOUGH_DATA); |
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.

What problem does this PR solve?
Issue Number: resolve N/A
Problem Summary:
IsPossiblyRtmpclaimed any connection whose first byte is 0x03 (the rtmp C0 version). RTMP is sniffed before thrift/http/redis/nshead andParseRtmpMessagepermanently binds the parsing context once it matches, so a frame of another protocol co-hosted on the same port that happens to start with 0x03 (for example a thrift request) was captured by the rtmp handshake state machine and the connection was broken.What is changed and the side effects?
Changed:
IsPossiblyRtmpnow requires the whole 1537-byte C0+C1 before claiming the connection and validates the version field of C1: zero for the simple handshake,adobe_hs::FP_VERSIONoradobe_hs::FMS_VERSIONfor the complex one. Fewer bytes return NOT_ENOUGH_DATA and an unsupported version returns TRY_OTHERS, so the other protocols sharing the port get a chance.adobe_hs::C1::Loadand the fallback to simple handshaking) is untouched.Side effects:
Performance effects: negligible. Only the first 9 bytes are inspected, and when the first byte is 0x03 the parser waits for 1537 buffered bytes before it either claims or rejects the connection.
Breaking backward compatibility: none. Client and server keeps working with simple, complex and simplified handshaking.
Check List:
Tests:
cmake -S . -B build -DBUILD_UNIT_TESTS=ON -DDOWNLOAD_GTEST=OFF -DBRPC_SYSTEM_GTEST_SOURCE_DIR=/usr/src/googletest && make -j6 brpc_rtmp_unittest./test/brpc_rtmp_unittest(36 cases, all passed). New cases:payload_starting_with_c0_version_tries_others,simple_handshake_accepted_after_c0c1_complete,complex_handshake_c1_is_accepted.🤖 This PR was automatically created by brpc-oncall