Skip to content

feat: Honor and save the Matroska track enabled flag in place - #140

Merged
decriptor merged 11 commits into
mainfrom
feat/matroska-track-enabled
Nov 22, 2026
Merged

decriptor merged 11 commits into
mainfrom
feat/matroska-track-enabled

Conversation

@decriptor

@decriptor decriptor commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Description

Matroska now reads and writes TrackEntry\FlagEnabled (0xB9).

Selection. The main audio and video track is the first enabled default track of that type, then the first enabled one. A track that stores FlagEnabled 0 can no longer win while an enabled track of its type exists. A missing or empty element counts as enabled (default 1).

API. MatroskaFile.Tracks (IReadOnlyList<MatroskaTrack>) lists the first 4096 known-size TrackEntry elements in file order (MatroskaFile.IsTrackListTruncated is true when a file has more; every entry still ranks for the main track) with TrackNumber, TrackUid, TrackType (new MatroskaTrackType, RFC 9559 Table 2), CodecId, IsDefault, and a settable IsEnabled. No per-track public API existed before; this is the smallest one that can carry a settable flag, shaped like FlacCueSheet.Tracks / FlacCueSheetTrack.

Saving (no element ever moves). Only a track whose IsEnabled the caller set is touched, and only when the stored value differs.

  • A stored 1 to 8 octet element is rewritten in place. The TrackEntry and Tracks CRC-32s are recomputed.
  • An empty or missing element becomes B9 81 0v. The TrackEntry and Tracks sizes grow, keeping their octet width when the new size fits. The extra octets come out of the Void directly after Tracks, which shrinks to nothing or to at least 2 octets. No element changes its segment position, so the SeekHead, Cues, and clusters keep their bytes.
  • Without that room the save fails ("... no Void right after Tracks can give them") and nothing is written. Using a Void anywhere else would move Info, Tracks, Tags or clusters.
  • DocTypeVersion. FlagEnabled has minver 2, and RFC 9559 §7 requires DocTypeVersion to be at least the highest element version. So when an element is added, a stored DocTypeVersion below 2 is raised in place, and an empty or missing one (which means 1) is written as 2. The EBML header grows by 1 octet (an empty element widened), 4 (a missing one added), or 5 (added, with the header size widening from 1 to 2 octets), or shrinks when an empty element was stored with a wide size (10 octets → 4: −6). Its CRC-32 is recomputed. The header is outside the Segment, so no Segment Position moves (round 1, F1).
  • Track identity. The track at each ordinal must still carry the TrackNumber and TrackUID it was read with, or the save fails. This guards SaveToFile(path, otherData).
  • Tags. The existing Tags rewrite then runs on the result. All save entry points (sync/async, path/data, Render) go through one TryRender. MatroskaRewrite.cs is unchanged apart from partial.

Motivation and Context

Issue #117: a disabled track could become the file's audio or video track, and the flag was neither read nor writable.

Closes #117

Spec references

  • RFC 9559 §5.1.4.1.4 FlagEnabled (0xB9, default 1, minver 2): "Set to 1 if the track is usable. It is possible to turn a track that is not usable into a usable track using chapter codecs or control tracks."
  • RFC 9559 §5.1.4.1.5 FlagDefault, §18.1 Default flag; §5.1.4.1.1-3 TrackNumber, TrackUID, TrackType (Table 2)
  • RFC 9559 §6.1 (Void padding "to avoid moving large amounts of data around"), §6.2 CRC-32, §16 Segment Position
  • RFC 8794 §6.1 (an empty element takes its default; a size need not use the shortest width), §7.2 (an unsigned integer is 0-8 octets), §11.2.7 DocTypeVersion, §11.3.1 CRC-32, §11.3.2 Void

Design decisions

  • Every track of a type disabled. The same ranking runs over the disabled tracks instead of reporting no audio or video. RFC 9559 §5.1.4.1.4 says a disabled track can still be made usable, so its media still describes the file, and MediaTypes stays consistent with TrackType. Documented on MatroskaTrack.
  • Setting IsEnabled is sticky. Disable, save, re-enable, save writes 1 again. Saving the same value twice gives identical bytes.
  • Elements over 8 octets (invalid per RFC 8794 §7.2) fail the save if the caller changes that track.
  • ChapterFlagEnabled (0x4598) is left to the chapter editor, as the issue says.

Out of scope (follow-up stacked PR)

Inserts that need elements to move. These are files without a Void right after Tracks: 11 of the 13 real files below, including all mkvmerge-era samples and ffmpeg output, where ffmpeg puts its Void after the SeekHead. Making room there means moving elements and patching the SeekHead, Cues, and Cluster\Position. That work is being done once for Tags, Chapters, Attachments and Tracks on fix/matroska-seekhead-fallback. A second PR stacked on that branch will route this insert through it. Until then those saves fail cleanly instead of writing a partial fix.

Existing main behavior, not changed here. An unchanged save already re-renders Tags. On test1/test6 it moves Tags to the segment end and drops their SeekHead entry. Every comparison below is against a main build's unchanged save of the same input.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)

Checklist

  • I have read the CONTRIBUTING guidelines
  • My code follows the project's code style
  • I have added tests that prove my fix/feature works
  • All new and existing tests pass (dotnet test)
  • I have updated documentation as needed (CHANGELOG Unreleased, README, docs/ROADMAP.md, public API snapshot)
  • My changes generate no new warnings

Testing

Gates

  • dotnet build -c Release: 0 warnings, 0 errors (netstandard2.0, netstandard2.1, net8.0, net10.0)
  • dotnet test -c Release (rebased on main 85ce8d2): net8.0 4528 passed, 13 skipped; net10.0 4528 passed, 13 skipped. The skips are env-gated integration tests.
  • dotnet format --verify-no-changes: clean

Unit tests (MatroskaTrackEnabledTests 12, MatroskaTrackEnabledSaveTests 34)

  • Read: disabled default loses (audio, video); ranking; every track disabled; missing/empty/0/1; track list fields; unlisted and huge TrackType; the stream read path; a truncation matrix that never throws.
  • Save, succeeds: untouched stays identical; in-place 1→0 and 0→1 change one byte; the Void after Tracks shrinks; a Void of exactly 3 octets is consumed; a 5-octet Void leaves 2; an empty element grows by 1; one-octet sizes widen; TrackEntry/Tracks CRC-32s; flag plus a Tags edit together; DocTypeVersion 1→2 with the header CRC; in-place leaves DocTypeVersion; unknown-size segment with a live cluster; a second Tracks element keeps ordinals; 200 Tracks elements; re-enable after save; both async overloads; in-place or Void insert with an unreadable SeekHead.
  • Save, fails and writes nothing: no Void; a Void before Tracks; a Void past a Cluster; a 4-octet Void (would leave 1); a different or missing track; a 9-octet flag; an unparsable TrackEntry.
  • Mutation check: I reverted each guard and the suite went red every time. Guards: Void remainder, Void-adjacency check, identity check, DocTypeVersion bump, TrackEntry CRC, enabled ignored in ranking, edits not collected, non-sticky set.

Integration (MatroskaIntegrationTests, env var TAGLIBSHARP2_TEST_MATROSKA), run locally against all 13 files below.

  • An untouched save keeps the Tracks and Cluster payloads: 13/13 files.
  • Toggling the first audio track round-trips with clusters unchanged and toggles back in place: Turning Lime and test5. It is inconclusive, by design, on the 11 files without a Void after Tracks.

Real files. Black-box tools: ffprobe/ffmpeg 8 and mediainfo 26.10. Neither reports FlagEnabled at all, so enzyme 0.5.2 (MIT, PyPI, used only as an independent reader) confirms the flag. A local EBML walker checks every CRC-32, every SeekHead entry, and every CueClusterPosition target.

Insert (track #2 disabled):

File Size vs main's unchanged save Clusters Seeks / cues land enzyme ffprobe Decode errors
Turning Lime.mkv (Void after Tracks) same 8 bytes, all in Tracks and the Void header identical, not moved 6/6; the one cue was already off in the original (670 vs 818) #2 DISABLED streams, tags and packet pos identical 0 (orig 0)
test5.mkv (11 tracks) same 352 bytes, all inside Tracks + Void header (later TrackEntries shift within Tracks) 25 identical 4/4, 46/46 #2 DISABLED, others unchanged packet pos identical; mediainfo identical apart from mtime 4 (orig 4)

Main audio after disabling: Turning Lime AAC 48000; test5 AAC 44100 (track #10, the enabled non-default track).

In place (re-enabling files that store the flag):

None of these files stores a FlagEnabled as shipped, and this PR refuses to add one to them (see "Refused" below). The inputs for this table are the disabled outputs of an earlier revision of this branch, 3bc9171, which still moved later elements to make room. With this head, the same inputs come from the stacked #148. From #140 alone, the reproducible in-place check is: insert the flag into Turning Lime or test5, which have a Void after Tracks, then toggle it back. The result differs by 1 byte, the clusters are identical, and the CRC, seek and cue checks pass, as the reviewer reproduced.

File vs main's unchanged save Clusters CRC-32 Seeks / cues enzyme Decode errors
test1, test6, multi.webm 1 byte (the flag) identical none stored land enabled 0
multi.mkv, audio.mka, live.mkv (ffmpeg) 5 bytes (flag + Tracks CRC) identical all match land enabled 0
test2, test3, test4, test7, test8 9 bytes (flag + TrackEntry and Tracks CRC) identical all match land enabled (test4 not readable by enzyme, original too) 0/0/0/1/0, same as originals

Refused (no Void after Tracks): test1-4, test6-8, and ffmpeg multi.mkv / multi.webm / audio.mka / live.mkv. Each save returns the error and writes nothing.

Generated with ffmpeg from lavfi sources: H.264 + 2 AAC with -disposition:a:1 default, VP9 + 2 Opus WebM, 2 FLAC mka, and -live 1 mkv.

Additional Notes

Implemented from RFC 9559 and RFC 8794 only. No media files are committed; tests build their inputs in code.

Round 1

Commits aa2f4f2 and 9efd129 (after the rebase onto main; they were f3f11be and 1af3193):

  • F1, DocTypeVersion: a missing or empty DocTypeVersion is now written as 2 when the flag is added (above). Tests: Save_InsertedFlag_AddsAMissingDocTypeVersion (+4 octets, header CRC valid, no Segment Position moved), Save_InsertedFlag_ReplacesAnEmptyDocTypeVersion (+1), and Save_InPlaceFlag_LeavesAMissingDocTypeVersion. The first two fail at 07724ed. The track fixtures now use an EBML header with DocTypeVersion 4, as muxers write it.

  • F2, track cap: MatroskaFile.Tracks keeps at most 4096 entries. Every entry still ranks for the main track. On the reviewer's many5m.mkv (5,000,000 empty entries), measured with the reviewer's mem.cs:

    • read time: 5608 → 1187 ms
    • allocated during read: 433.2 → 0.3 MiB
    • retained after GC: 326.7 → 10.2 MiB

    manytags.mkv is unchanged (the Tags follow-up). Test: Read_ManyTrackEntries_ExposesABoundedListButRanksThemAll, which fails at 8f5a6a6 (was 07724ed before the rebase) with 4597 tracks instead of 4096.

  • F3, PR body: the provenance of the in-place rows is stated above.

  • F4, IsFlagSet: FlagDefault and TagDefault now read through IsFlagSet. There is no behaviour change; the existing default-flag tests cover it.

Before/after, 8f5a6a6 (was 07724ed) vs 9efd129:

  • The reviewer's probe over 434 grid and special files, and MediaFile detection over the 573-file corpus: identical output.
  • Toggle saves over 443 inputs (specials, samples, Turning Lime, the reviewer's grid): byte-identical, except dtv_absent.mkv and dtv_empty.mkv. Those now carry DocTypeVersion 2, and enzyme, ffprobe and the decode check still read them cleanly.

Patch coverage on this PR's source lines vs main is 93%.

Round 2

Rebased onto main 85ce8d2. CHANGELOG now has this PR's ### Added block above the single ### Fixed list, and the #117 line is added to main's Fixed entries.

Round 3

Commits 72cac91 and d3f98af (head d3f98af):

  • Rename: MatroskaFile.TracksTruncated is now IsTrackListTruncated, matching the library's other public bools (Is/Has/Uses). It is unreleased, so the rename breaks no caller. The code, tests, PublicApi snapshot, CHANGELOG and this body are updated.
  • Duplicated DocTypeVersion (twin of feat: Move later Matroska elements when a track flag needs room #148 round 2): every DocTypeVersion copy below 2 is raised, and an empty copy is written as 2, as every FlagEnabled copy is. Test: Save_InsertedFlag_RaisesEveryDocTypeVersionCopy (cases (1, 4) → (2, 4), (1, empty) → (2, 2), and, from round 4 in c8da9a8, (empty, empty) → (2, 2), which turns red if only the first empty copy is replaced). The same code fails it on feat: Move later Matroska elements when a track flag needs room #148 at f6b9a29.
  • Round 1 section: the commit hashes now point at the rebased commits.

@codecov

codecov Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.61161% with 111 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.97%. Comparing base (85ce8d2) to head (c8da9a8).

Files with missing lines Patch % Lines
...bSharp2.Tests/Matroska/MatroskaIntegrationTests.cs 4.34% 66 Missing ⚠️
...rc/TagLibSharp2/Matroska/MatroskaRewrite.Tracks.cs 84.14% 19 Missing and 17 partials ⚠️
...Sharp2.Tests/Matroska/MatroskaTrackEnabledTests.cs 95.80% 3 Missing and 4 partials ⚠️
...p2.Tests/Matroska/MatroskaTrackEnabledSaveTests.cs 99.47% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #140      +/-   ##
==========================================
- Coverage   93.04%   92.97%   -0.07%     
==========================================
  Files         288      293       +5     
  Lines       57634    58521     +887     
  Branches     5510     5632     +122     
==========================================
+ Hits        53624    54410     +786     
- Misses       2334     2418      +84     
- Partials     1676     1693      +17     

☔ 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.

@decriptor decriptor changed the title feat: Honor and save the Matroska track enabled flag feat: Honor and save the Matroska track enabled flag in place Nov 21, 2026
decriptor added a commit that referenced this pull request Nov 21, 2026
Setting MatroskaTrack.IsEnabled writes FlagEnabled back on save. A
stored 1 to 8 octet element is rewritten in place. An empty or missing
one becomes a 3-octet element, and the TrackEntry and Tracks sizes grow
to hold it, keeping their width when the new size fits. The growth
comes out of the Void right after Tracks, so no element moves; without
that room the save fails and nothing is written. A stored
DocTypeVersion of 1 is raised to 2 when an element is added, since
FlagEnabled has minver 2.

A track the caller never set keeps its bytes. The track at each ordinal
must still carry the number and UID it was read with, or the save fails.
This is the same change as #140.
decriptor added a commit that referenced this pull request Nov 21, 2026
Setting MatroskaTrack.IsEnabled writes FlagEnabled back on save. A
stored 1 to 8 octet element is rewritten in place. An empty or missing
one becomes a 3-octet element, and the TrackEntry and Tracks sizes grow
to hold it, keeping their width when the new size fits. The growth
comes out of the Void right after Tracks, so no element moves; without
that room the save fails and nothing is written. A stored
DocTypeVersion of 1 is raised to 2 when an element is added, since
FlagEnabled has minver 2.

A track the caller never set keeps its bytes. The track at each ordinal
must still carry the number and UID it was read with, or the save fails.
This is the same change as #140.
decriptor added a commit that referenced this pull request Nov 21, 2026
The same change as #140 round 1 (its F2 and F4), applied to this stack:
MatroskaFile.Tracks keeps at most 4096 entries while every entry still
ranks for the main track, and FlagDefault and TagDefault share IsFlagSet.
decriptor added a commit that referenced this pull request Nov 21, 2026
Setting MatroskaTrack.IsEnabled writes FlagEnabled back on save. A
stored 1 to 8 octet element is rewritten in place. An empty or missing
one becomes a 3-octet element, and the TrackEntry and Tracks sizes grow
to hold it, keeping their width when the new size fits. The growth
comes out of the Void right after Tracks, so no element moves; without
that room the save fails and nothing is written. A stored
DocTypeVersion of 1 is raised to 2 when an element is added, since
FlagEnabled has minver 2.

A track the caller never set keeps its bytes. The track at each ordinal
must still carry the number and UID it was read with, or the save fails.
This is the same change as #140.
decriptor added a commit that referenced this pull request Nov 21, 2026
The same change as #140 round 1 (its F2 and F4), applied to this stack:
MatroskaFile.Tracks keeps at most 4096 entries while every entry still
ranks for the main track, and FlagDefault and TagDefault share IsFlagSet.
decriptor added a commit that referenced this pull request Nov 21, 2026
Setting MatroskaTrack.IsEnabled writes FlagEnabled back on save. A
stored 1 to 8 octet element is rewritten in place. An empty or missing
one becomes a 3-octet element, and the TrackEntry and Tracks sizes grow
to hold it, keeping their width when the new size fits. The growth
comes out of the Void right after Tracks, so no element moves; without
that room the save fails and nothing is written. A stored
DocTypeVersion of 1 is raised to 2 when an element is added, since
FlagEnabled has minver 2.

A track the caller never set keeps its bytes. The track at each ordinal
must still carry the number and UID it was read with, or the save fails.
This is the same change as #140.
decriptor added a commit that referenced this pull request Nov 21, 2026
The same change as #140 round 1 (its F2 and F4), applied to this stack:
MatroskaFile.Tracks keeps at most 4096 entries while every entry still
ranks for the main track, and FlagDefault and TagDefault share IsFlagSet.
FlagEnabled (0xB9) defaults to 1 and a stored 0 marks the track as not
usable (RFC 9559 5.1.4.1.4). The main audio and video track is now the
first enabled default track of that type, then the first enabled one.
When every track of a type is disabled, the same order runs over the
disabled tracks, since chapter codecs or control tracks can still make
them usable. A missing or empty element is enabled.

MatroskaFile.Tracks lists each known-size TrackEntry with its number,
UID, type, codec ID, default flag, and enabled flag.
Setting MatroskaTrack.IsEnabled writes FlagEnabled back on save. A
stored 1 to 8 octet element is rewritten in place. An empty or missing
one becomes a 3-octet element, and the TrackEntry and Tracks sizes grow
to hold it, keeping their width when the new size fits.

The growth comes out of the nearest Void that is not past a Cluster,
after Tracks first, so the clusters stay where they are. A Void that
would be left with one octet is skipped. Without a usable Void every
later element moves. SeekHead and Cues positions follow each piece to
where it landed, and the CRC-32 of every changed master is recomputed.
A stored DocTypeVersion of 1 is raised to 2 when an element is added,
since FlagEnabled has minver 2.

A track the caller never set keeps its bytes. The track at each ordinal
must still carry the number and UID it was read with, or the save fails.
The integration tests read TAGLIBSHARP2_TEST_MATROSKA, check that an
untouched save keeps the Tracks and Cluster payloads, and toggle the
first audio track and back.
An in-place FlagEnabled edit moves no element, so it no longer asks for
the strict SeekHead and Cues walk. A SeekHead the writer cannot read
only fails the save when an element it may name has moved.
A missing FlagEnabled now takes its room from the Void right after
Tracks, so no element changes its segment position and the SeekHead,
Cues, and clusters keep their bytes. Any other insert fails and writes
nothing. Moving later elements is left to the shared Matroska shift, so
MatroskaRewrite is back to its main behavior apart from being partial.
…ck list

Adding FlagEnabled (minver 2) makes the EBML header's DocTypeVersion at
least 2 (RFC 9559 section 7): a lower stored value is raised in place,
and an empty or missing one, which means 1, is written, growing the
header and its CRC. The header is outside the Segment, so no Segment
Position moves.

MatroskaFile.Tracks keeps at most 4096 entries. RFC 9559 sets no
maxOccurs on TrackEntry, and a 10 MB file of empty entries allocated
433 MiB; every entry still ranks for the main audio and video track.
FlagDefault and TagDefault read through IsFlagSet, like FlagEnabled.

The track fixtures use an EBML header with DocTypeVersion 4, as muxers
write it.
MatroskaFile.Tracks is documented as the first 4096 known-size
TrackEntry elements, and the new MatroskaFile.TracksTruncated is true
when a file had more, so a caller can tell a cut list from a full one.

Tests now pin the EBML header size widening when an added DocTypeVersion
takes 123 header octets to 127 (40 7F, +5), and the shrink when a wide
empty DocTypeVersion is replaced (-6).
@decriptor
decriptor force-pushed the feat/matroska-track-enabled branch from 1af3193 to dd09959 Compare November 21, 2026 19:49
decriptor added a commit that referenced this pull request Nov 21, 2026
The same change as #140 round 2 (its #1 and #3), applied to this stack:
MatroskaFile.Tracks is documented as the first 4096 known-size
TrackEntry elements, MatroskaFile.TracksTruncated says when a file had
more, and tests pin the EBML header size widening (+5, 40 7F) and the
wide empty DocTypeVersion shrink (-6).
decriptor added a commit that referenced this pull request Nov 21, 2026
Setting MatroskaTrack.IsEnabled writes FlagEnabled back on save. A
stored 1 to 8 octet element is rewritten in place. An empty or missing
one becomes a 3-octet element, and the TrackEntry and Tracks sizes grow
to hold it, keeping their width when the new size fits. The growth
comes out of the Void right after Tracks, so no element moves; without
that room the save fails and nothing is written. A stored
DocTypeVersion of 1 is raised to 2 when an element is added, since
FlagEnabled has minver 2.

A track the caller never set keeps its bytes. The track at each ordinal
must still carry the number and UID it was read with, or the save fails.
This is the same change as #140.
decriptor added a commit that referenced this pull request Nov 21, 2026
The same change as #140 round 1 (its F2 and F4), applied to this stack:
MatroskaFile.Tracks keeps at most 4096 entries while every entry still
ranks for the main track, and FlagDefault and TagDefault share IsFlagSet.
decriptor added a commit that referenced this pull request Nov 21, 2026
The same change as #140 round 2 (its #1 and #3), applied to this stack:
MatroskaFile.Tracks is documented as the first 4096 known-size
TrackEntry elements, MatroskaFile.TracksTruncated says when a file had
more, and tests pin the EBML header size widening (+5, 40 7F) and the
wide empty DocTypeVersion shrink (-6).
decriptor added a commit that referenced this pull request Nov 21, 2026
Setting MatroskaTrack.IsEnabled writes FlagEnabled back on save. A
stored 1 to 8 octet element is rewritten in place. An empty or missing
one becomes a 3-octet element, and the TrackEntry and Tracks sizes grow
to hold it, keeping their width when the new size fits. The growth
comes out of the Void right after Tracks, so no element moves; without
that room the save fails and nothing is written. A stored
DocTypeVersion of 1 is raised to 2 when an element is added, since
FlagEnabled has minver 2.

A track the caller never set keeps its bytes. The track at each ordinal
must still carry the number and UID it was read with, or the save fails.
This is the same change as #140.
decriptor added a commit that referenced this pull request Nov 21, 2026
The same change as #140 round 1 (its F2 and F4), applied to this stack:
MatroskaFile.Tracks keeps at most 4096 entries while every entry still
ranks for the main track, and FlagDefault and TagDefault share IsFlagSet.
decriptor added a commit that referenced this pull request Nov 21, 2026
The same change as #140 round 2 (its #1 and #3), applied to this stack:
MatroskaFile.Tracks is documented as the first 4096 known-size
TrackEntry elements, MatroskaFile.TracksTruncated says when a file had
more, and tests pin the EBML header size widening (+5, 40 7F) and the
wide empty DocTypeVersion shrink (-6).
Every other public bool in the library has an Is, Has or Uses prefix.
The property is unreleased, so the rename breaks no one.
DocTypeVersion has maxOccurs 1, but a file can store it twice. Every copy
below 2 is now raised, and an empty copy is written as 2, as every
FlagEnabled copy is written, so a reader that takes the first copy no
longer sees 1. The header CRC is recomputed only when a copy changed.
The same change as #148 round 2.
decriptor added a commit that referenced this pull request Nov 21, 2026
Every other public bool in the library has an Is, Has or Uses prefix.
The property is unreleased, so the rename breaks no one. The same change
as #140 round 3.
A header with two empty DocTypeVersion copies must end with both at 2.
Without this row, replacing only the first empty copy stayed green.
@decriptor

Copy link
Copy Markdown
Owner Author

Review: 0 findings at c8da9a8.

All findings from four review rounds are fixed, and the last round found nothing new.

What was checked at this head:

  • Selection: the main track is the first enabled default track of its type, then the first enabled one. A 416-input grid changed only the intended answers, and detection across 573 sample files is unchanged.
  • Saving: FlagEnabled is saved in place, so no Segment Position moves. An inserted flag raises DocTypeVersion to 2 per RFC 9559 §7 and RFC 8794 §11.2.7: every copy, including empty or duplicated copies. The EBML header size and CRC-32 are rebuilt. enzyme, ffprobe, mediainfo and an ffmpeg decode all read the outputs cleanly.
  • Large files: Tracks exposes at most the first 4096 entries; IsTrackListTruncated reports a cut list, and every entry still ranks for the main track. A 5-million-entry crafted file reads with 0.3 MiB allocated.
  • Robustness: fuzzing ran 58,686 truncated and byte-flipped inputs with 0 exceptions. Every targeted guard revert fails a test.
  • Builds and tests: Release build has 0 warnings on all four targets; tests pass on net8.0 and net10.0; format and CI are green, and the PR merges cleanly into main.

@decriptor decriptor added the approved AI has reviewed and signed off label Nov 21, 2026
decriptor added a commit that referenced this pull request Nov 21, 2026
Setting MatroskaTrack.IsEnabled writes FlagEnabled back on save. A
stored 1 to 8 octet element is rewritten in place. An empty or missing
one becomes a 3-octet element, and the TrackEntry and Tracks sizes grow
to hold it, keeping their width when the new size fits. The growth
comes out of the Void right after Tracks, so no element moves; without
that room the save fails and nothing is written. A stored
DocTypeVersion of 1 is raised to 2 when an element is added, since
FlagEnabled has minver 2.

A track the caller never set keeps its bytes. The track at each ordinal
must still carry the number and UID it was read with, or the save fails.
This is the same change as #140.
decriptor added a commit that referenced this pull request Nov 21, 2026
The same change as #140 round 1 (its F2 and F4), applied to this stack:
MatroskaFile.Tracks keeps at most 4096 entries while every entry still
ranks for the main track, and FlagDefault and TagDefault share IsFlagSet.
decriptor added a commit that referenced this pull request Nov 21, 2026
The same change as #140 round 2 (its #1 and #3), applied to this stack:
MatroskaFile.Tracks is documented as the first 4096 known-size
TrackEntry elements, MatroskaFile.TracksTruncated says when a file had
more, and tests pin the EBML header size widening (+5, 40 7F) and the
wide empty DocTypeVersion shrink (-6).
decriptor added a commit that referenced this pull request Nov 21, 2026
Every other public bool in the library has an Is, Has or Uses prefix.
The property is unreleased, so the rename breaks no one. The same change
as #140 round 3.
decriptor added a commit that referenced this pull request Nov 21, 2026
Setting MatroskaTrack.IsEnabled writes FlagEnabled back on save. A
stored 1 to 8 octet element is rewritten in place. An empty or missing
one becomes a 3-octet element, and the TrackEntry and Tracks sizes grow
to hold it, keeping their width when the new size fits. The growth
comes out of the Void right after Tracks, so no element moves; without
that room the save fails and nothing is written. A stored
DocTypeVersion of 1 is raised to 2 when an element is added, since
FlagEnabled has minver 2.

A track the caller never set keeps its bytes. The track at each ordinal
must still carry the number and UID it was read with, or the save fails.
This is the same change as #140.
decriptor added a commit that referenced this pull request Nov 21, 2026
The same change as #140 round 1 (its F2 and F4), applied to this stack:
MatroskaFile.Tracks keeps at most 4096 entries while every entry still
ranks for the main track, and FlagDefault and TagDefault share IsFlagSet.
decriptor added a commit that referenced this pull request Nov 21, 2026
The same change as #140 round 2 (its #1 and #3), applied to this stack:
MatroskaFile.Tracks is documented as the first 4096 known-size
TrackEntry elements, MatroskaFile.TracksTruncated says when a file had
more, and tests pin the EBML header size widening (+5, 40 7F) and the
wide empty DocTypeVersion shrink (-6).
decriptor added a commit that referenced this pull request Nov 21, 2026
Every other public bool in the library has an Is, Has or Uses prefix.
The property is unreleased, so the rename breaks no one. The same change
as #140 round 3.
decriptor added a commit that referenced this pull request Nov 22, 2026
Setting MatroskaTrack.IsEnabled writes FlagEnabled back on save. A
stored 1 to 8 octet element is rewritten in place. An empty or missing
one becomes a 3-octet element, and the TrackEntry and Tracks sizes grow
to hold it, keeping their width when the new size fits. The growth
comes out of the Void right after Tracks, so no element moves; without
that room the save fails and nothing is written. A stored
DocTypeVersion of 1 is raised to 2 when an element is added, since
FlagEnabled has minver 2.

A track the caller never set keeps its bytes. The track at each ordinal
must still carry the number and UID it was read with, or the save fails.
This is the same change as #140.
decriptor added a commit that referenced this pull request Nov 22, 2026
The same change as #140 round 1 (its F2 and F4), applied to this stack:
MatroskaFile.Tracks keeps at most 4096 entries while every entry still
ranks for the main track, and FlagDefault and TagDefault share IsFlagSet.
decriptor added a commit that referenced this pull request Nov 22, 2026
The same change as #140 round 2 (its #1 and #3), applied to this stack:
MatroskaFile.Tracks is documented as the first 4096 known-size
TrackEntry elements, MatroskaFile.TracksTruncated says when a file had
more, and tests pin the EBML header size widening (+5, 40 7F) and the
wide empty DocTypeVersion shrink (-6).
decriptor added a commit that referenced this pull request Nov 22, 2026
Every other public bool in the library has an Is, Has or Uses prefix.
The property is unreleased, so the rename breaks no one. The same change
as #140 round 3.
@decriptor
decriptor merged commit b2887cd into main Nov 22, 2026
8 checks passed
@decriptor
decriptor deleted the feat/matroska-track-enabled branch November 22, 2026 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved AI has reviewed and signed off

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Honor Matroska TrackFlagEnabled

1 participant