sahvx655-wq opened a new pull request, #3744: URL: https://github.com/apache/brpc/pull/3744
### What problem does this PR solve? Issue Number: N/A Problem Summary: `TsWriter::Write(const RtmpAudioMessage&)` in `src/brpc/ts.cpp` wraps each raw AAC frame in a 7-byte ADTS header. The ADTS `frame_length` field is 13 bits and counts the header as well as the payload, but the guard only rejects payloads above `0x1fff`. A raw AAC frame of 8185 to 8191 bytes gives `frame_length` 8192 to 8198, and the `& 0x03` / `& 0xff` / `& 0xe0` masks 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 `TsWriter` can 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: ``` payload=8185 adts_frame_length=0 payload=8190 adts_frame_length=5 payload=8191 adts_frame_length=6 ``` ### What is changed and the side effects? Changed: - Lower the bound in `TsWriter::Write` to `0x1fff - 7`, so the largest accepted raw frame is 8184 bytes and `frame_length` always fits its 13 bits. Oversized frames get the same `EINVAL` status the existing check already returns, and nothing is appended to the output buffer. - Add `RtmpTest.ts_writer_aac_frame_length_fits_adts_header` to `test/brpc_rtmp_unittest.cpp`. It checks that 8184 bytes still muxes with `frame_length` 8191 and that 8185 and 0x1fff bytes are rejected. It fails on master and passes with the fix; the full `brpc_rtmp_unittest` suite (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: - Please make sure your changes are compilable. - When providing us with a new feature, it is best to add related tests. - Please follow [Contributor Covenant Code of Conduct](https://github.com/apache/brpc/blob/master/CODE_OF_CONDUCT.md). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
