Skip to content

fix(rtcp,sctp): RFC 3550 compliance and SCTP INIT safety hardening#69

Open
nightness wants to merge 2 commits into
webrtc-rs:masterfrom
Brainwires:fix/rtcp-sctp-correctness
Open

fix(rtcp,sctp): RFC 3550 compliance and SCTP INIT safety hardening#69
nightness wants to merge 2 commits into
webrtc-rs:masterfrom
Brainwires:fix/rtcp-sctp-correctness

Conversation

@nightness
Copy link
Copy Markdown

@nightness nightness commented Apr 1, 2026

Summary

rtc-rtcp -- RFC 3550 section 6.4.1 compliance

ReceptionReport::total_lost was u32 but the field is defined by RFC 3550 as a signed 24-bit integer. Negative values occur when duplicate packets arrive (received > expected). This change:

  • Changes the field type to i32
  • Updates serialisation to validate against the signed 24-bit range and write two's-complement bytes
  • Updates deserialisation to sign-extend from bit 23

rtc-interceptor -- signed total_lost propagation

  • Updates ReceiverStream::total_lost from u32 to i32 to match the RTCP type change
  • Clamps to signed 24-bit max (0x7FFFFF) instead of unsigned (0xFFFFFF)

rtc-sctp -- SCTP INIT tag guard

handle_first_packet had a guard on line 214 that checked initiate_tag.is_none() before reaching the .unwrap() on line 239, but the compiler could not verify the coupling. Replaces the unwrap with a let Some(...) else { return None } guard directly at the use site -- self-documenting and compiler-verified.

rtc-stun -- restore error_code Display tests

Reverted the ErrorCodeAttribute::Display impl back to from_utf8_lossy (matching PR #64) because the from_utf8 + Err(fmt::Error) approach causes format!() to panic on invalid UTF-8 input. Restored the two test cases that verify this behavior.

Test Plan

  • cargo build -p rtc-rtcp -p rtc-sctp passes
  • cargo test -p rtc-rtcp -- 52 tests pass
  • cargo test -p rtc-stun -- 65 tests pass (including restored error_code tests)
  • cargo test -- full workspace passes (0 failures)
  • cargo clippy -- no warnings
  • cargo fmt --check -- clean

Generated with Claude Code

Copy link
Copy Markdown
Member

@rainliu rainliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good to me.

But please fix existing tests failure due to the above changes.

Copy link
Copy Markdown
Member

@rainliu rainliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix failure tests.

@nightness nightness requested a review from rainliu April 8, 2026 07:57
nightness and others added 2 commits April 10, 2026 00:14
rtc-rtcp: Change ReceptionReport::total_lost from u32 to i32 (RFC 3550
§6.4.1).  The field is a signed 24-bit integer; negative values occur
when duplicate packets cause received > expected.  Deserialization now
sign-extends from bit 23; serialisation validates against the signed
24-bit range (-8 388 608..=8 388 607).

rtc-sctp: Replace `initiate_tag.as_ref().unwrap()` with a compiler-
verified `let Some(...) else { return None }` guard.  The unwrap was
technically safe due to an earlier check on line 214, but that coupling
was invisible to the compiler.  The new guard is self-documenting and
eliminates the brittle dependency.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The reception_report::total_lost field was changed from u32 to i32
(signed 24-bit per RFC 3550 §6.4.1). Update the interceptor's
ReceiverStream to use i32 and clamp to the signed 24-bit max (0x7FFFFF)
instead of the unsigned 0xFFFFFF.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nightness nightness force-pushed the fix/rtcp-sctp-correctness branch from 633b171 to e5e7ab3 Compare April 10, 2026 05:14
@nightness
Copy link
Copy Markdown
Author

Rebased onto upstream/master so this PR contains only its own changes. Previous branch structure caused merge conflicts when PRs were merged in sequence. Each PR is now independently mergeable.

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.

2 participants