Files
ZLMediaKit/tests
YuLi b0427c3901 VP9 RTP parser: add robust bounds checks, fix pictureID and references, add unit tests (#4790)
### 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)
2026-08-02 13:06:34 +08:00
..
2024-11-29 23:51:34 +08:00
2026-01-08 21:18:00 +08:00
2025-09-22 21:06:17 +08:00
2023-12-09 16:23:51 +08:00
2026-01-08 21:18:00 +08:00
2024-11-29 23:51:34 +08:00

此目录下的所有.cpp文件将被编译成可执行程序(不包含此目录下的子目录). 子目录DeviceHK为海康IPC的适配程序,需要先下载海康的SDK才能编译, 由于操作麻烦,所以仅把源码放在这里仅供参考.

  • test_benchmark.cpp

    rtsp/rtmp性能测试客户端

  • test_httpApi.cpp

    http api 测试服务器

  • test_httpClient.cpp

    http 测试客户端

  • test_player.cpp

    rtsp/rtmp带视频渲染的客户端

  • test_pusher.cpp

    先拉流再推流的测试客户端

  • test_pusherMp4.cpp

    解复用mp4文件再推流的测试客户端

  • test_server.cpp

    rtsp/rtmp/http等服务器

  • test_wsClient.cpp

    websocket测试客户端

  • test_wsServer.cpp

    websocket回显测试服务器