Skip to content

fix: preserve label boundaries in DNS name compression - #542

Merged
keepsimple1 merged 2 commits into
keepsimple1:mainfrom
Sealdot:codex/fix-dns-compression-label-boundaries
Nov 14, 2026
Merged

keepsimple1 merged 2 commits into
keepsimple1:mainfrom
Sealdot:codex/fix-dns-compression-label-boundaries

Conversation

@Sealdot

@Sealdot Sealdot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #541.

write_name joins unescaped labels with dots to index previously written suffixes. As a result, L\.A.B.local. and L.A.B.local. share a key even though their label sequences differ. The second name can become a pointer to the first name on the wire.

Index suffixes by their length-prefixed label bytes instead. This preserves exact label boundaries and UTF-8 bytes, queries borrowed suffix slices, and copies a suffix into the index only when recording a new entry. Existing label validation, packet rollback and packet splitting continue to use the same paths. Ordinary names still compress against identical names and shared suffixes.

Four regression tests check the actual wire bytes and pointer targets. They cover both insertion orders, suffix collisions, dots with backslashes, equivalent escaped names, a 63-byte UTF-8 label in a legal 255-byte name, and exact-fit/spill packet limits. Existing serialization byte expectations are retained.

Validation

On macOS aarch64, Rust 1.97.1, one Cargo job and one test thread:

  • Same four regression assertions: original writer 1 passed / 3 failed; final writer 4 passed.
  • Complete library suites on the same implementation: default 94 passed; all features 95 passed; no failures or ignored library tests.
  • Both repository formatting commands and both strict Clippy commands passed.
  • Documentation with warnings denied passed. Doc-tests: 4 passed, 3 existing ignored.
  • Rust 1.71.0: cargo check --all-features and cargo check --no-default-features passed with the same dependency lock.
  • Applied the exact fix: escape dots and backslashes in labels read from packets #540 patch at 2840d279 locally: 34 parser/supplemental tests passed, including the read-side escaping and wire-length regressions.
  • A separate local byte-label audit checked 225 ordered name pairs and rollback/retry. The original writer produced 12 incorrect pairs; the fixed writer produced none. This supplemental probe is outside this patch.

The full library/documentation runs preceded a final test-only change qualifying three MSG_HEADER_LEN references so the tests also compile with #540. The implementation and assertions are identical. The final source was rechecked with the four regressions, formatting, all-target/all-feature strict Clippy, MSRV checks, and the #540 combination.

Initial validation attempts are retained in the local evidence: Rust 1.71 offline resolution could not find the cached index, so it was rerun successfully with a task-local sparse online index. The first #540 combination did not compile because #540 removed an import used by the new tests; the three qualified constant references described above fixed that test-only issue.

The integration test executables, cross-host network behavior, Windows/Linux, CI's Rust 1.99.1, and nightly fuzz builds were not run locally. No external CI was manually triggered.

AI assistance

OpenAI Codex assisted with the implementation, tests, local review, and this draft.

Fixes keepsimple1#541.

AI assistance: OpenAI Codex assisted with implementation, tests, and local review.
@keepsimple1

Copy link
Copy Markdown
Owner

Thanks for your PR. If you feel your PR is ready for review, please click "Ready for review" so that Github updates its status.

@Sealdot
Sealdot marked this pull request as ready for review November 12, 2026 06:54
@Sealdot

Sealdot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Thanks! CI is green and the change is complete on my side — marked ready for review.

@keepsimple1 keepsimple1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

LGTM with two small nits inlines. Thanks!

Comment thread src/dns_parser.rs Resolved
Comment thread src/dns_parser.rs Resolved
Maintainer review on keepsimple1#542: the \A case is unrelated to the fix and may change; trailing-dot equivalence is already covered by test_dns_outgoing_compression_max_length_labels.
@keepsimple1
keepsimple1 merged commit 1d9aa6f into keepsimple1:main Nov 14, 2026
6 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.

write_name compression can point to the wrong name when a label contains a dot

2 participants