Repository navigation
docs: Add an implementation guide and a shared verification kit - #152
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #152 +/- ##
========================================
Coverage 93.25% 93.26%
========================================
Files 364 376 +12
Lines 76942 77692 +750
Branches 8305 8407 +102
========================================
+ Hits 71754 72458 +704
- Misses 3057 3083 +26
- Partials 2131 2151 +20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
decriptor
force-pushed
the
feat/dev-kit
branch
from
November 22, 2026 17:54
ddcd0eb to
dafc5b1
Compare
… 6.1 for empty elements
…name the example's commit
decriptor
force-pushed
the
feat/dev-kit
branch
from
November 22, 2026 18:42
dafc5b1 to
332c9fa
Compare
Owner
Author
|
Review: 0 findings at 332c9fa. What was checked:
|
9 of 12 tasks
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.
Description
This PR adds a development process guide and a shared verification kit. With them, an implementer can run the checks that reviews have been running in rounds 3 to 8, before the PR is opened. No library code changes.
docs/IMPLEMENTATION-GUIDE.mdcovers the process:Clear()and null remove all tag metadata, mapped and unmapped, with only the exceptions main has a reason for: Audible's decryption keys and identifiers, Matroska non-image attachments, required fields such as the Vorbis vendor string, and chapters; assigning a tag andCopyTokeep unmapped items), plus main's known gaps (Matroska Info/Title, Audible user_alias);It is linked from
CONTRIBUTING.md,CLAUDE.mdanddocs/NEW-FORMAT-CHECKLIST.md. The PR template gains four checklist items: design note, twin table, kit run and pre-review.Test kit (
tests/TagLibSharp2.Tests/Kit/), each helper with its own tests:Bounds:AllocatedBytes,AssertAllocatesAtMost, andAssertLinearAllocation. The linear check compares increments over n, 2n and 4n, so a fixed cost cannot hide quadratic growth.CountingStreamis the operation counter for stream paths.Hostile:EveryTruncationandByteFlips. Each runs every case, then fails once with the count and the first offsets and exceptions.Nesting: one-pass builders for 100,000-level EBML chains (8-octet sizes), ISO BMFF chains (64-bit sizes), RIFF LIST chains, and ID3v2.4 CHAP and CTOC embedded-frame chains.DepthCases,DepthProbe,KitChildandKitProgram. The test assembly re-runs itself withdotnet exec TagLibSharp2.Tests.dll kit-depth <case> <depth>, on a 1 MiB stack with a 1 GiB GC heap limit. A stack overflow then fails one test instead of aborting the run. The test project setsGenerateProgramFile=false, soKitProgram.Mainreplaces the empty entry point that the test SDK generates. The test host never calls it.NestingDepthTestsis a class-level depth test. EveryDepthCaseruns at 100,000 levels through span, stream, async and path reads, a tag edit and a save, then a re-read. A case passes when nothing crashes or throws, and a successful save reads back with the edit. A bounded refusal also passes. Rows come fromDepthCases.All, so a new case is tested without a new test method.Folded into the kit, coverage unchanged:
MalformedInputTests;GC.GetAllocatedBytesForCurrentThreadpairs inApeTagTests,Id3v2FrameFlagsTestsandAiffAnnotationTests.tools/(local only, documented with example output intools/README.md):compare/grid.cs: before/after grid.--lib <worktree>builds a copy against another checkout's library.compare/readers.sh: ffprobe, exiftool (-G1, so stale copies show), mutagen and mediainfo, side by side.fuzz/fuzz.cs: truncation and byte-flip fuzz over real files: span, stream and a no-op save.mutation.sh: Stryker.NET on the files changed since a base.Corpora come from arguments or
TAGLIBSHARP2_TEST_CORPUS, plus the existingTAGLIBSHARP2_TEST_*file variables. No media is committed, and TagLib# is not referenced anywhere.Mutation testing:
dotnet-stryker5.1.0 (latest stable) is pinned in.config/dotnet-tools.json.tests/TagLibSharp2.Tests/stryker-config.jsonscopes it tosrc/TagLibSharp2and the test project.Motivation and Context
Across the last 17 PRs, reviews kept finding issues the implementer never checked:
The reviewers had better tools and better context. This PR puts those tools, and the lessons learned, into the repository.
Type of Change
Tests and local tooling only. The package is unchanged.
Checklist
dotnet test)Implementation guide
DepthCases.Allis the list, andNestingDepthTestsruns it.IgnoreMessage-skipped rather than asserted to fail.StackBytes = 64 MiBturns it red;readers.shmaps exiftool AlbumTitle, DateCreated and DateTimeOriginal, mutagen WM/PartOfSet and ffprobe date_recorded, and showsn/awhen mutagen cannot read a format (swept over WMA, AVI, MKV, M4A, FLAC, MP3, OGG, WAV, APE, MPC, Opus, AIFF, DSF and AAC); the README example names its commit.Nesting structures on main
matroska-simpletagmatroska-cuesmatroska-chaptersMatroskaChapters.MaxDepth= 32)mp4-udtaMp4BoxParser.ParseBox/ParseChildrenat 100k (about 1,600 levels fit in 1 MiB). Each level also copies its payload, so memory grows with the square of the depth; an earlier build hit the 1 GiB cap first.mp4-track-layoutmp4-udta;CollectTrackLayoutrecurses on the same pathwav-listmp3-id3v2-chapmp3-id3v2-ctocThe two failing MP4 rows are skipped through
TestDataRow.IgnoreMessage, which is the per-row form of[Ignore], each with its reason. The Matroska rows now run and pass on main. ASF, AIFF, DSF, DFF, FLAC, Ogg, APE, WavPack, Musepack and MPEG-PS have no structure whose depth the file controls.Repro for any row:
dotnet exec tests/TagLibSharp2.Tests/bin/Release/net10.0/TagLibSharp2.Tests.dll kit-depth <case> 100000. To see the MP4 overflow without hitting the memory limit, usekit-depth mp4-udta 5000.Testing
Gates at the head:
dotnet build -c Release: 0 warnings, 0 errors, for netstandard2.0, netstandard2.1, net8.0 and net10.0.dotnet test -c Release:f1ecb88).DOTNET_TieredCompilation=0.dotnet format --verify-no-changes: clean.dotnet pack -c Release: packs.dotnet list package --vulnerable --include-transitive: none.dotnet dotnet-coverage collect ... "dotnet test --no-build ...".Kit run, with each tool run on the real samples (example output is in
tools/README.md):--libpointed at a worktree of4ef8e24~1(before MPEG-PS). 10 of 49 lines differ, each traced to a commit in between (MPEG-PS, AAC, the Matroska no-op save, MP3 and WAV save fixes); seetools/README.md.tools/mutation.sh HEADwith a one-line edit toExtendedFloat.cs: 58 mutants, 84.48%, 3 minutes 8 seconds, and no file left behind (PublicApi tests are filtered out,*.received.*is ignored, and the script removes any new received file). Earlier,tools/mutation.sh origin/main~2(one file,MpegPsScanner.cs, 578 mutants tested) took 22 minutes on a loaded machine, with a score of 72.03%. The setup alone (build, the first test run and coverage capture of 23,258 mutants) takes 3 to 12 minutes. That is too slow for CI, so it stays local only.--sincefinds no changes in a git worktree.tools/mutation.shworks around both: it takes the files fromgit diffand selects an installed 10.0 SDK through a temporaryglobal.json.Additional Notes
The kit found these bugs on main. They are not fixed here (no library code in this PR):
SaveToFilethrowsInvalidOperationException: Cannot render invalid WAV filefromWavFile.Render. Repro:WavFile.Read (File.ReadAllBytes ("sample.wav")[..12]).File!.SaveToFile ("out.wav").MediaFile.Read (path)does not setSourcePathfor MP3 and FLAC, becauseMp3File.Read (stream)andFlacFile.Read (stream)are called without it.file.SaveToFile (newPath)then fails with "No source path available". MP4 is fine.MediaFile.Read (path).Tagis theId3v2Tagonly.Tag.Clear ()followed by a save leaves RIFF INFO, so a re-read still showsTitle,Artistand the other fields.ParseBoxcopies each nested payload (new BinaryData (remaining.Slice (...))). Memory is therefore quadratic in the nesting depth, about 1 GiB by 500 levels of a 1.6 MB file.