Repository navigation
Fix desync after unknown type - #352
Merged
Merged
Conversation
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 Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
🟢 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
approved these changes
Oct 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.