Skip to content

Fix desync after unknown type - #352

Merged
digizeph merged 3 commits into
bgpkit:mainfrom
ties:fix-desync-after-unknown-type
Oct 11, 2026
Merged

digizeph merged 3 commits into
bgpkit:mainfrom
ties:fix-desync-after-unknown-type

Conversation

@ties

@ties ties commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

First (LLM) pass at fixing a desync issue after an unknown type. When a record type is unknown the header is read (12b) but the code aborted before the body is read.

That means that the next read will start at the start of the BGP message content and (in practice) would fail.

ties added 3 commits October 11, 2026 13:40
The parser de-synced after a MRT record of unknown type. The header
was consumed, but the body was not. Since the length of the body is
known from the header, this can be read to prevent a desync after
this type of record.
Read the common header's length separately from validating its
contents, so chunk_mrt_record reads the body of every record the same
way and rejects an unknown entry type (or an ET length below four)
only once the record is consumed. This replaces header_error, which
guessed the case from the error type and bytes consumed and repeated
the 16 MiB check.

A truncated unknown-type body now reports the truncated-body I/O
error, like any other record. Rename RawMrtRecordError::aligned to
record_consumed: reading the declared body does not prove the record
started on a real boundary.

Assisted-by: Claude Code
Keep the "length is untrusted, so stop" reasoning on the
OversizedRecord variant and shorten the call sites and changelog
entries that repeated it. Fix the test-helper length (32, not 8), the
oversized_record() doc that described bytes its callers append, and
the torn-write test comments that implied skipping the unknown-type
record restores alignment. Credit the framing fixes in the changelog's
Contributors section.

Assisted-by: Claude Code
@codecov

codecov Bot commented Oct 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.80952% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.16%. Comparing base (395a9ef) to head (8359c3d).

Files with missing lines Patch % Lines
src/parser/mrt/mrt_record.rs 98.58% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #352      +/-   ##
==========================================
+ Coverage   92.12%   92.16%   +0.04%     
==========================================
  Files          96       96              
  Lines       23534    23661     +127     
==========================================
+ Hits        21680    21807     +127     
  Misses       1854     1854              

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

Framing, error propagation, iterator termination, and regression coverage are consistent with the intended fix.

0 open findings

What changed in this PR

Fixes MRT stream desynchronization by consuming bounded bodies for rejected headers before continuing iteration.

Changes:

  • Separates MRT header framing from validation.
  • Adds explicit oversized-record handling.
  • Expands iterator alignment and corruption tests.
File Description
src/​error.rs Adds OversizedRecord.
src/​parser/​mrt/​mrt_header.rs Separates framing and validation.
src/​parser/​mrt/​mrt_record.rs Consumes rejected record bodies safely.
src/​parser/​iters/​mod.rs Defines iterator termination behavior.
src/​parser/​iters/​default.rs Registers alignment tests.
src/​parser/​iters/​default/​tests.rs Tests default and fallible iterators.
src/​parser/​iters/​diagnostic.rs Continues after fully consumed rejected records.
src/​parser/​iters/​route.rs Updates route iterator expectations.
tests/​torn_mrt_records.rs Updates damaged-fixture diagnostics.
CHANGELOG.md Documents behavior and API changes.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@digizeph
digizeph merged commit af782f9 into bgpkit:main Oct 11, 2026
9 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.

3 participants