Repository navigation
fix(mux): a TS import ends on a packet header it cannot parse - #9243
Conversation
Quest-Claim: 37eed389d662f0bd
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 13 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
There was a problem hiding this comment.
ℹ️ No critical issues — one doc claim overreaches.
Approach: sound. It applies #9170's rule to the packet-header paths at the single points where they're parsed, and it keeps loss, TEI, PMT revision, and EOF truncation as damage.
Reviewed changes
Reviewed the full diff at 2eb74ba against main.
- Malformed adaptation field ends the import:
Import::packetreturnsError::Malformednaming the PID for any carried non-Ignoredstream or the PCR PID, before the clock reads it. Ignored PIDs never reachpes_packet(import.rsroute match), so they can't end anything. - PES header parse unified:
pes_packetnow flushes the prior PES and hands every start topes_header, which turnsheader_lenandparsefailures intoError::Malformed. - Header truncated at the next start ends the import: the change relies on every damage path (
damage,salvage,scrambled,end_route) already clearingheaders, and I checked that each one does. - PES-level scrambling on decoded streams is refused, not damaged: it goes through
scrambled(), so it counts inrefused, the warning is shared, and the route is kept. - Tests and docs: the old damage tests are rewritten as end-with-cause tests, scrambled and ignored-PID cases are added, and the
Programscollision test now expects the end.
claude-opus-5-5 | 𝕏
…clear, like any carriage Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed dd98e9f, which resolves the earlier finding by giving PES scrambling one rule on every carriage.
- Whole-PES scrambling is refused until clear:
handle_pes_startnow checkspes.scrambled()beforerefusal()and routes every carriage throughscrambled(). A KLV, DVB AC-3, or private PES stream keeps its route and catalog entry, and it resumes at the next clear PES instead of ending. refusal()drops scrambling: it now lists only header-export and clock-field refusals. Thestats::Stream::refuseddoc anddoc/bin/ts.mdmatch the new behavior.- Tests:
a_scrambled_pes_is_refused_until_clearchecks that the PES on each side publishes, the track ends cleanly, andrefused == 1. The scrambling case is gone from the refuse-the-stream table.
claude-opus-5-5 | 𝕏

Closes the quest quest/m1/ts-packet-abort.md and deletes it.
Problem
moq-mux's TS import counted an intact, unflagged adaptation field or PES header that does not parse as
damagedand resumed at the next PES. Over UDP and SRT a packet arrives whole or not at all, and RF corruption sets the transport error indicator, so such a header is a muxer bug or an unexplained flip. The maintainer's rule (2026-11-18): "We should not try to support random bit flips that we don't understand and limp along with broken functionality." moq-dev/moq#9170 applied it to undecodable units and left these packet-level paths.Approach
In
rs/moq-mux/src/container/ts/import.rs:Error::Malformed(naming the PID) before its clock bits are read. A PID the import does not carry (Stream::Ignored) is still not read, so its header cannot end anything.Error::Malformed, after the preceding PES flushes, so the units ahead of it still publish.pes_packetnow hands every start topes_header, removing the duplicated parse.PES_scrambling_control) goes through the same path as TS-level scrambling on every carriage: counted inrefused, warned once per PID, its unit lost, and the stream resumes once clear (video at its next keyframe). Previously it counted as damage on a decoded stream and ended a whole-PES (pesPacket) track for good.Docs:
doc/bin/ts.mdanddoc/bin/srt.mdsay a header that arrives whole but does not parse ends the import/session;Error's doc says which faults are damage and which end the import.Decisions
Made within the quest's remit, for review:
refuse(), not damage). Conditional access is a known source, so it is not damage;refuse()would end the track and drop the PID for good, while TS-level scrambling, the common CA case, already refuses per packet and resumes when clear. Matching that keeps one rule for scrambling, so it applies to whole-PES carriage (KLV, DVB AC-3, private PES) too, whichrefusal()used to end for good (Pullfrog's finding). Tests:scrambled_pes_is_refused_until_clear,a_scrambled_pes_is_refused_until_clear.Programsmultiplex: any program's import error already ends the wholeProgramsdecode (as for fix(mux): a TS import ends on a unit it cannot decode #9170's undecodable unit).a_corrupt_pmt_counts_once_whoever_reads_it's last case maps one program's audio PID onto another program's PMT PID, an illegal PID collision, so it now expects the end (the scan still counts the CRC error first).Impact
refusedrather thandamaged, and no longer ends a whole-PES track.Validation
just ci: all 4937 Rust tests and every check pass.moq-relayandmoq, ran a local relay withtest/ts/relay.toml, and piped a 6 s ffmpeg H.264+AAC TS throughmoq import tswith one video packet altered:Error: malformed TS adaptation field on PID 256.Error: PES header on PID 256: unexpected PES header marker bits.dropped a damaged TS unit ... error=transport error indicator,damaged=1.PES_scrambling_controlset: keeps publishing, logs the scrambling refusal,refused=1on the video PID.malformed_headers_end_the_import(PES, adaptation, adaptation carrying a PCR flag; checks the clock never moved, no damage counted, and the four pictures ahead published),invalid_adaptation_fields_end_the_import_on_media_and_clock_pids(media, dedicated PCR, and an ignored PID that must not end it),malformed_pes_start_ends_the_import_after_the_unit_before_it,malformed_pes_prefix_ends_the_import_without_waiting_for_more_bytes,pes_length_overruns_fail_before_waiting_for_the_optional_header,pes_fragmented_header_resets_on_loss_and_eof_and_ends_at_a_new_start.damaged_tei_recoversandclean_video_has_no_damagekeep the damage path covered.a_scrambled_pes_is_refused_until_clear(KLV PES, scrambled PES, KLV PES) publishes the first and third, keeps the track and its catalog entry, ends it cleanly, and countsrefused=1. With theimport.rsfix reverted it fails (the track leaves the catalog).cargo test -p moq-mux --lib container::ts: 774 pass;just checkpasses. Not run on the binary: the path is the same importer call the CLI makes, and the earlier binary run covered the decoded case.Caused by
No single PR: counting malformed headers as damage is as old as the import's damage handling, and became wrong when the maintainer set the rule on 2026-11-18.
Alternatives
refuse()): rejected above, since TS-level scrambling resumes when clear.Follow-ups
None. Open PRs touching the same file, for merge awareness: moq-dev/moq#9105, moq-dev/moq#9069.
Models
Size: S
Implementer: Claude, claude-opus-5-5, unknown effort (arm A)
Implementer: Claude Code, claude-opus-5-5, unknown effort (iterate, S, arm A)
🤖 Generated with Claude Code
(Written by Claude Opus 5.5)
Review
Rewritten by
quest reviewafter each round.Head: dd98e9f
Base: origin/main at ba44b82
Risk: medium,
TS and SRT import users now lose the session on malformed intact headers, while PES scrambling changes refusal and recovery behavior; no API or wire format changes, and a revert restores the previous behavior.Classified: medium by Codex, gpt-6.1-sol, low effort, session
01a1fb9e-df25-7692-bd2a-fd99ea2072eeReviewer: Codex, gpt-6.1-sol, medium effort
Session:
01a1fb9e-f994-7472-8942-ea802749d422, round 1Score: 9/10,
Source review found no actionable defects and supports landing, with builds and tests intentionally not run.Rounds: 2; first round 0; findings 0: fixed 0, refuted 0, open 0
Findings: none