Skip to content

fix(interceptor): clamp total_lost to signed 24-bit max per RFC 3550#77

Open
nightness wants to merge 3 commits into
webrtc-rs:masterfrom
Brainwires:fix/interceptor-total-lost
Open

fix(interceptor): clamp total_lost to signed 24-bit max per RFC 3550#77
nightness wants to merge 3 commits into
webrtc-rs:masterfrom
Brainwires:fix/interceptor-total-lost

Conversation

@nightness
Copy link
Copy Markdown

@nightness nightness commented Apr 1, 2026

Summary

  • receiver_stream.rs: fix the total_lost clamp from 0xFFFFFF (unsigned 24-bit max = 16,777,215) to 0x7FFFFF (signed 24-bit positive max = 8,388,607).
  • Introduce MAX_TOTAL_LOST named constant for the signed 24-bit ceiling, replacing bare 0x7FFFFF literals.
  • Clamp total_lost_since_report before adding to self.total_lost and use saturating_add to prevent overflow/wrap.
  • Reword doc comments on MAX_TOTAL_LOST and ReceptionReport.total_lost to clarify u32 storage clamped to signed 24-bit positive range for RFC 3550 wire format.
  • Fix marshal bounds check from >= (1 << 25) to > 0xFF_FFFF (correct 24-bit limit).

RFC 3550 §6.4.1 defines total_lost as a 24-bit signed integer. The RTCP reception report structure marshals it as a signed value (see rtc-rtcp PR #69 which adds the > 0x7F_FFFF bounds check). The previous clamp at 0xFFFFFF allowed values between 0x800000 and 0xFFFFFF to pass, which are in-range for unsigned 24-bit but out-of-range for signed 24-bit — those values would fail or produce incorrect RTCP reports.

Test plan

  • Existing receiver report tests pass
  • High-loss scenarios: total_lost is clamped at 8,388,607 rather than wrapping or failing RTCP serialization
  • cargo fmt --check passes
  • cargo clippy passes
  • Marshal boundary tests: 0xFF_FFFF accepted, 0x100_0000 rejected
  • Doc comments clarify u32 storage with signed 24-bit clamping

@nightness nightness force-pushed the fix/interceptor-total-lost branch 3 times, most recently from 7267904 to 65f0c5d Compare April 1, 2026 19:03
@nightness nightness changed the title fix(interceptor): cast total_lost to i32 for RFC 3550 compliance fix(interceptor): clamp total_lost to signed 24-bit max per RFC 3550 Apr 1, 2026
@rainliu rainliu requested a review from Copilot April 4, 2026 14:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates RTCP receiver report loss handling to respect RFC 3550’s definition of total_lost as a signed 24-bit value, preventing out-of-range values that break/incorrectly serialize reception reports.

Changes:

  • Clamp total_lost/total_lost_since_report to 0x7FFFFF instead of 0xFFFFFF.
  • Update inline comment to reference RFC 3550 §6.4.1 signed 24-bit definition.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread rtc-interceptor/src/report/receiver_stream.rs Outdated
Comment thread rtc-interceptor/src/report/receiver_stream.rs Outdated
nightness added a commit to Brainwires/webrtc-rs-rtc that referenced this pull request Apr 8, 2026
- Introduce MAX_TOTAL_LOST named constant (0x7F_FFFF) for the signed
  24-bit ceiling per RFC 3550 §6.4.1
- Clamp total_lost_since_report before adding to self.total_lost,
  and use saturating_add to prevent overflow/wrap
- Fix test assertion from 0xFFFFFF to MAX_TOTAL_LOST (0x7F_FFFF)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nightness nightness requested a review from Copilot April 8, 2026 08:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread rtc-interceptor/src/report/receiver_stream.rs Outdated
nightness added a commit to Brainwires/webrtc-rs-rtc that referenced this pull request Apr 8, 2026
- Reword MAX_TOTAL_LOST doc to explain u32 storage clamped to signed
  24-bit positive range for RFC 3550 wire format
- Add matching doc on ReceptionReport.total_lost field
- Fix marshal bounds check from (1 << 25) to 0xFF_FFFF (correct 24-bit
  limit)
- Add boundary tests for 24-bit marshal limit (0xFF_FFFF ok, 0x100_0000
  rejected)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
nightness and others added 3 commits April 10, 2026 00:16
RFC 3550 §6.4.1 defines total_lost as a 24-bit signed integer. The
previous clamp used 0xFFFFFF (unsigned 24-bit max = 16,777,215) which
allowed values that overflow the signed 24-bit range. Fix the clamp to
0x7FFFFF (signed 24-bit positive max = 8,388,607) so values are always
representable in the reception report field.
- Introduce MAX_TOTAL_LOST named constant (0x7F_FFFF) for the signed
  24-bit ceiling per RFC 3550 §6.4.1
- Clamp total_lost_since_report before adding to self.total_lost,
  and use saturating_add to prevent overflow/wrap
- Fix test assertion from 0xFFFFFF to MAX_TOTAL_LOST (0x7F_FFFF)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Reword MAX_TOTAL_LOST doc to explain u32 storage clamped to signed
  24-bit positive range for RFC 3550 wire format
- Add matching doc on ReceptionReport.total_lost field
- Fix marshal bounds check from (1 << 25) to 0xFF_FFFF (correct 24-bit
  limit)
- Add boundary tests for 24-bit marshal limit (0xFF_FFFF ok, 0x100_0000
  rejected)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nightness nightness force-pushed the fix/interceptor-total-lost branch from 600462f to 6a8d164 Compare April 10, 2026 05:16
@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