Skip to content

fix(dpi): keep STUN SOFTWARE when the byte cap splits a character - #753

Merged
domcyrus merged 3 commits into
domcyrus:mainfrom
JROtto5:fix/stun-software-utf8-cap
Nov 26, 2026
Merged

domcyrus merged 3 commits into
domcyrus:mainfrom
JROtto5:fix/stun-software-utf8-cap

Conversation

@JROtto5

@JROtto5 JROtto5 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The STUN SOFTWARE attribute is capped at 128 bytes before it is decoded. If a longer value has its 128th byte inside a multi-byte UTF-8 character, from_utf8 fails and the whole value is dropped. RFC 8489 §14.14 allows fewer than 128 characters (up to 763 bytes), so a valid non-ASCII SOFTWARE value can hit this. The parser now keeps the complete characters before the cut. Invalid UTF-8 is still rejected.

Verification

Run on Linux (x86_64). This machine has no libpcap or libelf headers, so the crates that link pcap and the ebpf feature were not built. None of them changed.

  • cargo fmt --all -- --check
  • cargo clippy --locked --workspace --all-targets -- -D warnings (--no-default-features --features landlock,macos-sandbox,kubernetes)
  • cargo test --locked -p rustnet-core: 709 passed. test_software_cap_splitting_a_character_keeps_the_prefix fails on main and passes here. test_software_cap_splitting_an_invalid_character_is_rejected (an invalid continuation right after the cap) fails on the first commit and passes here. test_software_invalid_utf8_is_rejected passes on both.

Scope

  • One feature or fix per PR (no unrelated cleanups bundled in)
  • I reviewed the changes and the description matches the diff
  • No new dependencies
  • No #[allow(clippy::...)] suppressions
  • User-visible changes are added to the ## [Unreleased] section of CHANGELOG.md

Notes for the reviewer

The prefix is kept only when the attribute is longer than the cap, the decode error is an incomplete sequence at the end (error_len() is None), and the character split by the cap is valid in the full value. An invalid byte inside the first 128 bytes, an invalid continuation after the cap, or a truncated character in a value under the cap still returns None.

The 128-byte cap on the SOFTWARE attribute can cut a multi-byte UTF-8
character, and from_utf8 then rejects the whole value. RFC 8489 allows
fewer than 128 characters (up to 763 bytes), so a valid non-ASCII value
longer than 128 bytes was dropped. Keep the complete characters before
the cut; invalid UTF-8 is still rejected.
JROtto5 and others added 2 commits November 26, 2026 07:03
Review feedback: check the bytes across the cap form a valid character
before keeping the prefix, and use an RFC 8489-compliant 127-character
fixture.
@domcyrus

Copy link
Copy Markdown
Owner

Thanks a lot for the fix and for following up on both review comments, @JROtto5! I added a small bound on the UTF-8 scan and a four-byte character case. All 718 core tests passed locally.

@domcyrus
domcyrus merged commit 515ddfa into domcyrus:main Nov 26, 2026
26 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