Skip to content

fix(rtp): add marshal-side bounds checks for CSRC count, extension lengths, and NALU sizes#74

Open
nightness wants to merge 1 commit intowebrtc-rs:masterfrom
Brainwires:fix/rtp-bounds-checks
Open

fix(rtp): add marshal-side bounds checks for CSRC count, extension lengths, and NALU sizes#74
nightness wants to merge 1 commit intowebrtc-rs:masterfrom
Brainwires:fix/rtp-bounds-checks

Conversation

@nightness
Copy link
Copy Markdown

Summary

  • RTP header CSRC count: RFC 3550 §5.1 defines CC as a 4-bit field (max 15). Previously self.csrc.len() as u8 would silently truncate; now returns Error::TooManyCSRCs(n) if > 15.
  • One-byte extension payload: RFC 8285 §4.2 requires 1–16 bytes. Previously payload.len() as u8 - 1 would wrap/truncate on 0-length or >16-byte payloads; now returns Error::OneByteHeaderExtensionPayloadTooLarge(n).
  • Two-byte extension payload: RFC 8285 §4.3 max 255 bytes. Previously payload.len() as u8 silently truncated; now returns Error::TwoByteHeaderExtensionPayloadTooLarge(n).
  • H.264 STAP-A NALU length: Aggregation length field is u16; oversized NALUs are now skipped rather than having their length field silently truncated.
  • H.265 aggregation NALU length: Same fix — NALUs > 65535 bytes are skipped in the aggregation loop.

Parse-side already has bounds checks; this brings marshal-side to parity.

Test plan

  • cargo test -p rtc-rtp — all 99 existing tests pass
  • Manually verify Header::marshal_to() returns Err(TooManyCSRCs(16)) for a header with 16 CSRCs
  • Verify one-byte extension rejects 0-byte and 17-byte payloads
  • Verify two-byte extension rejects 256-byte payload

🤖 Generated with Claude Code

…ngths, and NALU sizes

RFC 3550 §5.1: CC is a 4-bit field (max 15 CSRCs); return TooManyCSRCs error if exceeded.
RFC 8285 §4.2/4.3: one-byte extension payload must be 1–16 bytes, two-byte max 255 bytes;
return errors rather than silently truncating via `as u8` cast.
H.264/H.265 aggregation length fields are u16; skip NALUs > 65535 bytes instead of
silently truncating their length field.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@nightness nightness force-pushed the fix/rtp-bounds-checks branch from 5b00e71 to da14873 Compare April 1, 2026 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant