Repository navigation
bound aac frame to the 13-bit adts frame_length in TsWriter::Write - #3744
Open
sahvx655-wq wants to merge 1 commit into
Open
sahvx655-wq wants to merge 1 commit into
sahvx655-wq wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain, and the change includes boundary-focused regression coverage for valid and oversized AAC payload handling.
No open issues 🎉
What changed in this PR
This pull request fixes AAC-to-ADTS muxing in TsWriter::Write by ensuring the 13-bit ADTS frame_length field includes the 7-byte header without overflow.
Changes:
- Restricts raw AAC payloads to 8184 bytes.
- Rejects oversized payloads before writing output.
- Adds regression coverage for valid and rejected frame-size boundaries.
| File | Description |
|---|---|
| test/brpc_rtmp_unittest.cpp | Adds regression tests and supporting helpers for AAC ADTS frame-length boundary encoding and oversized-payload rejection. |
| src/brpc/ts.cpp | Adjusts the AAC payload-size guard so the complete ADTS frame length fits within the 13-bit field. |
Review effort: Lite
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: N/A
Problem Summary:
TsWriter::Write(const RtmpAudioMessage&)insrc/brpc/ts.cppwraps each raw AAC frame in a 7-byte ADTS header. The ADTSframe_lengthfield is 13 bits and counts the header as well as the payload, but the guard only rejects payloads above0x1fff. A raw AAC frame of 8185 to 8191 bytes givesframe_length8192 to 8198, and the& 0x03/& 0xff/& 0xe0masks truncate that to 0 to 6. The muxer then writes an ADTS header claiming the frame is shorter than the header itself, and every TS/HLS consumer reads the publisher's payload bytes that follow as further ADTS frames.The frame size comes straight from the RTMP publisher, so any client that can publish to a server muxing with
TsWritercan trigger it with a single oversized audio message. I found it by reading how the size guard lines up with the bit packing below it, then confirmed it with a test that writes an AAC sequence header followed by raw frames of increasing size. On master the emitted headers decode as:What is changed and the side effects?
Changed:
TsWriter::Writeto0x1fff - 7, so the largest accepted raw frame is 8184 bytes andframe_lengthalways fits its 13 bits. Oversized frames get the sameEINVALstatus the existing check already returns, and nothing is appended to the output buffer.RtmpTest.ts_writer_aac_frame_length_fits_adts_headertotest/brpc_rtmp_unittest.cpp. It checks that 8184 bytes still muxes withframe_length8191 and that 8185 and 0x1fff bytes are rejected. It fails on master and passes with the fix; the fullbrpc_rtmp_unittestsuite (34 tests) passes locally on macOS.Side effects:
Performance effects: none, the change is one constant in an existing comparison.
Breaking backward compatibility: AAC frames of 8185 to 8191 bytes are now rejected instead of being written with a corrupt ADTS header. A single ADTS frame cannot legally carry them, so no valid stream is affected.
Check List: