mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-08-04 23:52:35 +08:00
### Motivation - Harden VP9 RTP payload parsing against malformed/truncated packets to avoid OOB reads and crashes. - Fix incorrect assembly of extended `pictureID` and incorrect consumption of reference indices in flexible mode. - Add focused unit tests to cover descriptor variants and edge cases so regressions are caught automatically. ### Description - Change parser signature to `int parse(const unsigned char *data, int dataLength)` and replace raw pointer arithmetic with `readByte`/`skipBytes` helpers that track remaining bytes and enforce bounds. - Fix `largePictureID` assembly by concatenating bytes correctly instead of using `ntohs` arithmetic, and ensure `additionalReferenceIdx` is set from the parsed byte; also limit flexible-mode reference chain to at most three references. - Parse scalability-structure fields (`spatialLayers`, `hasResolution`, `hasGof`) with bounds checks and correctly read resolution entries and GOF reference indices; return `-1` on truncation. - Add an extra safety check in `VP9RtpDecoder::decodeRtp` to verify the parsed header offset is within payload bounds, and add `tests/test_vp9_rtp.cpp` with many descriptor/edge-case cases exercising parsing logic. ### Testing - Added unit test `tests/test_vp9_rtp.cpp` covering L/F/P combinations, picture ID variants, reference chains, resolution and GOF parsing, and truncation cases, and executed it as an automated test. - The new test binary completed all test cases successfully (all expected pass/fail outcomes matched). ------ [Codex Task](https://chatgpt.com/codex/cloud/tasks/task_e_6a63e97a4c2c8320aa66d51a746c2e4d)
11 KiB
11 KiB