Skip to content

Ignore ERROR-CODE reserved bits when decoding class - #286

Merged
JoTurk merged 1 commit into
pion:mainfrom
dngr2:errorcode-reserved-bits
Aug 18, 2026
Merged

JoTurk merged 1 commit into
pion:mainfrom
dngr2:errorcode-reserved-bits

Conversation

@dngr2

@dngr2 dngr2 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

The ERROR-CODE value's third byte holds a 3-bit Class in its low bits; the upper 5 bits are Reserved. RFC 5389 §15.6 (and RFC 8489 §14.8) say the Reserved bits SHOULD be 0 and receivers MUST ignore them.

GetFrom read the entire byte as Class, so an ERROR-CODE arriving with reserved bits set decodes to a wrong code — e.g. class byte 0xE4 (low bits = 4) + number 20 should be 420 but decodes to 22820 — and a value the decoder accepts then fails AddTo (class > errorCodeClassMax), so the library can't re-emit what it just parsed. Masking the class with 0x7 fixes both. Number is genuinely 8 bits, so only the class byte needs masking. Added a test; full suite stays green.

@codecov

codecov Bot commented Aug 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.43%. Comparing base (57b10ab) to head (6bfea88).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #286   +/-   ##
=======================================
  Coverage   66.43%   66.43%           
=======================================
  Files          27       27           
  Lines        2124     2124           
=======================================
  Hits         1411     1411           
  Misses        700      700           
  Partials       13       13           
Flag Coverage Δ
go 66.43% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dngr2
dngr2 force-pushed the errorcode-reserved-bits branch from f9e0ec2 to 8dc92a3 Compare August 17, 2026 20:56

@JoTurk JoTurk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good catch, Thank you.

The class byte holds a 3-bit Class in its low bits; the upper 5 are Reserved.
RFC 5389 15.6 and RFC 8489 14.8 say receivers MUST ignore those bits, but
GetFrom read the whole byte, so an ERROR-CODE with reserved bits set decoded
to a wrong code (420 -> 22820) and could not be re-encoded. Mask with 0x7.
@JoTurk
JoTurk force-pushed the errorcode-reserved-bits branch from 8dc92a3 to 6bfea88 Compare August 18, 2026 12:55
@JoTurk

JoTurk commented Aug 18, 2026

Copy link
Copy Markdown
Member

I'll merge and tag this once the CI passes, somehow related pion/turn#581 :)

@JoTurk
JoTurk merged commit 7b40f80 into pion:main Aug 18, 2026
17 of 18 checks passed
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