Skip to content

fix: Return an AIFF annotation as the comment - #135

Merged
decriptor merged 13 commits into
mainfrom
fix/aiff-comment
Nov 22, 2026
Merged

decriptor merged 13 commits into
mainfrom
fix/aiff-comment

Conversation

@decriptor

@decriptor decriptor commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

AIFF comments, titles, artists and copyrights come from the native text chunks without being copied into ID3, and later edits go to ID3.

Breaking change. AiffFile.Tag was a settable Id3v2Tag?. It is now a get-only Tag? view over the ID3 chunk and the native chunks. The ID3 tag itself is the new AiffFile.Id3v2Tag property (get and set). Code that assigned aiff.Tag, or used ID3-only members on it, has to move to aiff.Id3v2Tag. aiff.Tag.Render() throws NotSupportedException, like the other combined views; render the AiffFile. The CHANGELOG lists this under Breaking Changes.

Read. Comment, Title, Artist and Copyright return the ID3 value when it is non-empty, otherwise the native ANNO/COMT, NAME, AUTH or (c) text. A COMT entry with marker id 0 is the file comment and ranks above ANNO. Entries for other marker ids are not the file comment. Every other Tag member is forwarded to the ID3 tag. Native text is Mac OS Roman, or UTF-8 when the whole value is valid UTF-8 and contains a multibyte sequence. A leading space is kept, so TOS_DVDSTEREOMIX.aif reads Creator: Logic. Duration stays 734.000 seconds. The sound data is not loaded. TagType reports native text as RiffInfo, because TagTypes has no AIFF member.

Write. Any set of Title, Artist, Comment, Copyright or Performers writes ID3 and removes that field's native chunks on save. That includes a native-only field and a set to the value it already has, so a reader that only looks at NAME/ANNO/COMT no longer sees an edited field. Native chunks are never rewritten. When a comment edit removes a COMT file comment, the notes for other markers stay in COMT byte for byte. A comment over 64 KB and a file that already has lyrics both save. Clearing a field stays cleared. An unchanged save does not add an ID3 chunk and keeps the native chunks as they are.

Also changes WAV. Id3v2Tag.IsEmpty now checks every frame kind, not only the basic fields. WAV and AIFF write the ID3 chunk only when it is not empty, so a WAV save used to drop an ID3 tag that held only, for example, a composer, a publisher, lyrics or a BPM. It now keeps it.

Fixes #127

@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.26804% with 105 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.02%. Comparing base (b2887cd) to head (5fd0ac6).

Files with missing lines Patch % Lines
src/TagLibSharp2/Aiff/AiffTag.cs 56.96% 0 Missing and 71 partials ⚠️
...sts/TagLibSharp2.Tests/Aiff/AiffAnnotationTests.cs 98.01% 1 Missing and 13 partials ⚠️
tests/TagLibSharp2.Tests/Aiff/AiffTagViewTests.cs 88.54% 3 Missing and 8 partials ⚠️
tests/TagLibSharp2.Tests/Core/TagMemberSamples.cs 93.84% 1 Missing and 3 partials ⚠️
src/TagLibSharp2/Aiff/AiffFile.cs 98.32% 0 Missing and 3 partials ⚠️
...s/TagLibSharp2.Tests/Riff/WavFileRoundTripTests.cs 84.61% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #135      +/-   ##
==========================================
+ Coverage   92.97%   93.02%   +0.04%     
==========================================
  Files         293      298       +5     
  Lines       58521    59830    +1309     
  Branches     5632     5862     +230     
==========================================
+ Hits        54410    55654    +1244     
+ Misses       2418     2395      -23     
- Partials     1693     1781      +88     

☔ 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

Copy link
Copy Markdown
Owner Author

Review: 0 findings at 007684c.

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

What was checked at this head:

  • Comment and annotation fields: checked against AIFF 1.3 / AIFF-C (COMT, ANNO, NAME, AUTH, (c), MARK). After edits, CoreAudio (afinfo), ffprobe, mediainfo, exiftool, mutagen and TagLib# all read the new title, artist, comment and copyright.
  • Marker notes: notes for markers other than 0, including empty and NUL-only notes, keep their bytes on every comment-edit and Clear path.
  • Several COMT chunks: files with more than one COMT chunk are never written with more chunks than the input had. Notes keep their order and are spread evenly, so a count of 65,535 (which hangs MediaInfo 26.10) is written only when the input leaves no other choice. A 633-input boundary sweep showed 0 violations.
  • Robustness: fuzzing ran 185,831 inputs with 0 failures. 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, codecov/patch is above 92%, and the PR merges cleanly into main.

@decriptor decriptor added the approved AI has reviewed and signed off label Nov 21, 2026
A FORM AIFF may contain more than one ANNO chunk and more than one COMT chunk. The first was kept and the rest were dropped. A trailing NUL counted inside a COMT string is not part of the comment.

Fixes #127
The COMT text count includes one leading space before Creator: Logic.
A trailing space in the text stays.

Fixes #127
Comment, title, artist, and copyright prefer a non-empty ID3 field and otherwise the native chunk. Save rewrites each model from itself, so clearing a comment does not restore COMT or ANNO text.
A comment, title, artist, or copyright set by the caller is stored on the ID3 tag, including a comment longer than a COMT field and a file that already has lyrics or a rating. Native chunks are kept only for text read from those chunks and not overridden, and rewritten text uses Mac OS Roman. The combined tag is a cached get-only view that forwards the rest of the Tag surface.
Walk every settable Tag member through the AIFF view, a WAV save and
Id3v2Tag.IsEmpty so a member that stops forwarding or an ID3 tag that
saves as empty fails a test. Bound the many-ANNO read by allocated bytes
instead of wall-clock time, and cover each UTF-8 lead-byte class,
including a sequence cut off at the end of the chunk.
…write

A comment edit re-encoded the notes of other markers from their decoded
text, so a UTF-8 note became Mac OS Roman and a trailing NUL was lost.
Write each note's bytes as read. Every edit already moves the field to
ID3, so the native rewrite branches, the Mac OS Roman encoder and the
save-time InvalidOperationException catch had nothing left to handle.
Remove them and say in the remarks that ID3 is the only write target.
List the AiffFile.Tag type change and the wider Id3v2Tag.IsEmpty as
breaking changes, and show AIFF's native chunks in the README table.
…otes

A comment edit or Clear rewrote COMT from the notes it had read, but notes
with no text or only NULs were never kept, so they were lost. Keep every
note for a marker other than 0. Write at most 65,535 notes per COMT chunk
so numComments cannot wrap, and report TagType from the same fields as
IsEmpty, so marker notes alone are not a tag.
…ment-edit guard

Split notes from several COMT chunks over the fewest chunks that hold
them, evenly, so a chunk is full only when the input's were (MediaInfo
26.10 hangs on a count of 65,535). Cite the Comments Chunk rule instead
of a section that does not exist, and test that a save without a comment
edit keeps every COMT chunk byte for byte.
… must

Use min(ceil(n / 65,534), input COMT chunks) chunks. That still never
writes more chunks than the file had, and writes a count of 65,535 only
when the notes do not fit 65,534 to a chunk. Pin the split at the
65,535 and 131,070 boundaries and on three- and four-chunk inputs.
@decriptor

Copy link
Copy Markdown
Owner Author

Review: 0 findings at 5fd0ac6 (rebase of the approved 007684c onto main b2887cd).

What was checked:

  • git range-diff: only CHANGELOG lines changed. No code changes.
  • The CHANGELOG keeps main's track-enabled entries and this PR's Breaking/Added/Fixed entries, with no duplicates.
  • Release build: 0 warnings. net8.0 and net10.0: 4607 passed / 13 skipped. Format clean. CI is all green, including codecov.

@decriptor
decriptor merged commit 4910102 into main Nov 22, 2026
8 checks passed
@decriptor
decriptor deleted the fix/aiff-comment branch November 22, 2026 01:59
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.

[Bug]: AIFF annotation is not returned as the comment

1 participant