Repository navigation
fix: Drop a terminating NUL from ID3 text - #136
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #136 +/- ##
==========================================
+ Coverage 93.07% 93.34% +0.27%
==========================================
Files 298 319 +21
Lines 61380 66207 +4827
Branches 6067 6752 +685
==========================================
+ Hits 57129 61803 +4674
- Misses 2420 2462 +42
- Partials 1831 1942 +111 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
decriptor
force-pushed
the
fix/id3-trailing-nul
branch
from
November 21, 2026 07:12
a194d18 to
4cc0afb
Compare
9 of 12 tasks
decriptor
force-pushed
the
fix/id3-trailing-nul
branch
2 times, most recently
from
November 22, 2026 01:55
abe696c to
203bbbf
Compare
The single-value composer and album artist are the first entry. Copying them after the array replaced the list with that one name. Fixes #128
A Basic copy still copies only the first artist and genre. That is the Basic contract. APE overrides of the performer, album artist, composer, and genre lists are what keep the extra names. UTF-16 values each use their own BOM. A comment or lyric ends at the first NUL. A leading NUL is an empty first value, not a skipped one.
Setting or clearing album artists removes both Album Artist and ALBUMARTIST. Artist, album artist, composer, and genre return the first name. A copy into MP4 or ASF still keeps only that first name.
Setting or clearing an APE year also removes Date, so an old date cannot come back. A locator or an empty text item reads the same string for a name as it does for a title. A Vorbis original-release write also removes ORIGINALYEAR, and a movement write also removes MOVEMENTNAME. The changelog records that an APE artist is the first name, and that a Basic copy into MP4, ASF, RIFF INFO, or ID3v1 keeps that first name.
AlbumArtist returned a locator URL as soon as Album Artist had one, while AlbumArtists skipped that non-text item and read ALBUMARTIST. A text name on either key is the first album artist. A locator is used only when neither key has text.
Original release date reads TDOR or TORY, but a write only replaced one of them, so clearing the property brought the other frame back. Movement reads MVNM or MVIN before the TXXX field, so a write to TXXX left the Apple frame in front. A write now updates both, and a clear removes both. Setting one half of MVIN keeps the other half.
Clearing the number from MVIN "1/4" alone must keep the total 4, which only the TXXX:MOVEMENTTOTAL rewrite preserves once MVIN is removed. The existing step now uses a total that differs from the number, so a swap of the two halves fails.
A Vorbis movement or original release date write removed MOVEMENTNAME or ORIGINALYEAR even when the value was set, not cleared. Picard keeps the movement name in MOVEMENTNAME beside a MOVEMENT number, and the original year in ORIGINALYEAR beside ORIGINALDATE, so an editor writing back the values it showed erased them. An APE year write removed Date in the same way. Now only a clear removes the fallback. Writing back the value already read changes nothing. A new value also replaces an existing fallback: the name in MOVEMENTNAME, the four-digit year in ORIGINALYEAR, and the year in Date.
The movement remarks now name MVNM and MVIN for ID3v2. The changelog records the new ID3v2 MVNM and MVIN writes, the TDOR and TORY clear, and the narrowed Vorbis and APE fallback rule.
Clearing the total from MVIN "2/5" must leave TXXX:MOVEMENTNUMBER holding 2, so a reader that only looks at TXXX still sees the number.
A single-value getter returns the first name of a multi-value ID3v2 frame, APE item, or repeated Vorbis field, and the setter stored that one name in place of the list. An editor that writes back what it read erased every other artist, composer, or genre. Every ID3v2 text and TXXX property, every APE text property, and every Vorbis text field now leaves the tag alone when the value equals what the getter returns, an empty string included. The ID3v2 movement number, total, and original release date follow the same rule. Any other value still replaces the list, and null still clears it. An empty MOVEMENT, ORIGINALDATE, APE Year, or ID3v2 MVNM no longer hides a filled fallback, and a TDOR or TORY without a date no longer hides the other frame. Before, the getter returned the empty value and writing it back deleted the fallback. An ID3v2 genre whose first value is empty reads as an empty string, like the other text frames.
The write-back no-op compared the copied value with the target's first value, so a copy into a Picard-style tag left the target's other labels, ISRCs, catalog numbers, artists, and genres in place. CopyTo now turns the no-op off on its thread while it writes, which also covers tags a wrapper forwards to, so the target holds exactly the source value. The rule lives in one place, Tag.IsWriteBack. An empty string counted as a write-back whenever the getter read "", so "" no longer cleared an ID3v2 frame or Vorbis field whose first value is empty and whose later values hold text. It is now a write-back only when no value holds text, which is when the APE getter reads "" too. The ID3v2 year, podcast feed URL, and MusicBrainz recording ID setters get the same guard, so a v2.3 year write-back no longer rewrites TYER as UTF-8. A case-only edit and a null over a field that reads null are pinned as writes.
A copy of the value a Vorbis movement or original date already reads rewrote MOVEMENTNAME or ORIGINALYEAR to it, so copying one Picard tag into another set MOVEMENTNAME to the movement number. An APE year copy in the same way cut Date down to the year. The fallback is its own field, so a copy of the value read leaves it, as it did before the write-back rule, and only drops the other values of the primary field.
A single-value getter read an empty first value as "", so writing it back counted as a clear and deleted the frame or field. ID3v2.4 stores several strings as a NUL-separated list and Vorbis field names repeat, so the getters now return the first non-empty value, and "" only when every value is empty. A write-back of what was read keeps the frame, and "" still clears it. This replaces reading a leading NUL as an empty first value. CopyTo now reads every source value before it writes any, skips a list the target already holds, and treats a copy from the target itself, or from a view that reads from it such as Mp3File.Tag or FlacFile.Tag, as a write-back. Before, the first write cut the lists the copy then read, so a file's view copied into its own tag kept only the first artist, genre, label, and catalog number. A copy of the original date a v2.3 tag already reads no longer drops the TDOR full date beside TORY. A Vorbis or APE movement laid out as Picard writes it, with the number in MOVEMENT beside MOVEMENTNAME, reads and writes the name in MOVEMENTNAME and the number in MOVEMENT, so a copy no longer writes the number over an ID3v2 MVNM. The ID3v2 comment and lyrics setters get the write-back guard, and the byte identity test now uses foreign frame layouts.
Mp3File.Tag builds a new combined view on every read, so a copy from one read into another was not seen as a copy between views over the same tag, and its single-value lists were cut. Tags now expose the tags they read from, and a copy between two that share one skips every value the target already shows. A copy with Extended carries the artist and genre in their lists, so a list the target holds keeps its frames. The ID3v2 comment and lyrics read the first non-empty frame, as text frames do, so a write-back of what is shown changes nothing and "" clears the frames without a description. Vorbis and APE movements follow Picard's tag mapping: the name is MOVEMENTNAME and the number is MOVEMENT. A MOVEMENT that is not a number is still read as the name when no MOVEMENTNAME exists. Clearing one half no longer changes how the other half reads.
A tag that holds one name took the first entry of a copied list even when it was empty, so a default copy of ARTIST= plus ARTIST=V2 into MP4, ASF, RIFF INFO, or ID3v1 cleared the artist and genre and dropped the target's old ones. The base list setters and RIFF INFO's now keep the first non-empty entry, the one the source shows. Also pin the lyrics fallback to a described frame.
AiffTag reads the file's ID3 tag, but it did not name it, so a copy between aiff.Tag and aiff.Id3v2Tag ran as a copy between unrelated tags and cut TPUB and the other single-value lists. It now lists that tag in Leaves, and a test checks every Tag type that holds another tag or a file of tags. The ID3v2.4 list reading trimmed every value and dropped blank ones, while the single value kept them, so a Basic copy and the default copy stored different names for " \0B". A NUL-separated value is now kept as written and only an empty one is skipped, as other readers show it.
decriptor
force-pushed
the
fix/id3-trailing-nul
branch
from
November 22, 2026 02:17
203bbbf to
0477a14
Compare
The view guard looked for fields of a few shapes, so a view holding its tags in an IEnumerable, a delegate, a base class's private field, or a non-public holder member passed. Every concrete Tag type must now be a listed leaf format tag or override Leaves, so a new type fails until someone decides which it is.
…name A subclass of a view, or a type that inherits a Leaves written for its base, could add a tag of its own and still pass, and so could a type reusing a leaf's simple name. Each view must now declare Leaves itself, leaf tags are listed by full name, and eleven dummy views, one per shape, pin the guard. The GetTextFrameValues remark no longer says the first entry differs for a plain value.
TagTypeClassification holds the leaf list, the view and leaf rules, and the library's view and unclassified lists, so other checks can use the same rule as the guard.
Owner
Author
|
Review: 0 findings at 2c5b459. What was checked:
|
8 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.
A trailing ID3 terminator is not part of the string.
sample.mp3andsample.wavcomment isyepa. The single-value getter returns the first value, sonull_title_v2.mp3title isT. A leading NUL does not hide the next value: the ID3v2 and Vorbis single-value getters (and the publicGetTextFrame,GetUserText,VorbisComment.GetValue) return the first non-empty value (ID3v2.4 §4.2 multiple strings), and "" only when every value is empty. A value is kept as written (only an empty one is skipped), andGetTextFrameValuesand the ID3v2 list properties follow the same rule for NUL-separated values, so for those the single value and the first list entry agree. A value with/and no NUL is still split on/and trimmed in any version (AC/DCreads ArtistAC/DC, Performers [AC,DC]), as before. This deliberately differs from mutagen and TagLib#, which return the empty first ID3v2 value. The comment and lyrics read the first non-empty frame without a description, then the first other one, as ffprobe and TagLib# show it. Each UTF-16 value may carry its own BOM. A comment or unsynchronized lyric ends at the first NUL. A synchronized-lyric NUL ends that line only.APE list fields keep every performer, album artist, composer, and genre, NUL-separated. The singular getters return the first of those names, not a comma-joined string. A Basic copy from APE keeps that first name. Setting or clearing album artists removes both item names, so a stale value does not remain. Clearing the year also removes
Date; setting a new year also writes it to an existingDate. A text album artist on either item wins over a locator. A lone locator or an empty text item reads the same string for a name as it does for a title. A binary item reads as null.A copy into MP4, ASF, RIFF INFO, or ID3v1 still stores one name: the first non-empty one, so
ARTIST=+ARTIST=V2storesV2under the defaultAllcopy too. That is the single-value contract on those tags. A copy into ID3v2 keeps the full list. Real list support for MP4 and ASF is #137.Clearing a Vorbis original release date also removes
ORIGINALYEAR, and a new date rewrites an existingORIGINALYEARto its four-digit year. Writing back the APE year, Vorbis original release date, or Vorbis movement already read changes nothing, so a Picard or Mp3tag tag keepsMOVEMENTNAME,ORIGINALYEAR, andDate.Setting a new ID3 original release date, or clearing it, removes both
TDORandTORY. A movement write stores the same name inMVNMandTXXX:MOVEMENT. Setting one half ofMVINkeeps the other half.Writing back the value a single-value property returned changes nothing (ordinal comparison), in every ID3v2 string property (text and TXXX frames, year, comment, lyrics, podcast URL, MusicBrainz recording ID), every APE text property, and every Vorbis text field. So an editor that writes back what it showed keeps every value of a multi-value artist, album artist, composer, genre, label or other field, and keeps the fallback fields.
= ""and null clear (for a comment or lyrics, every frame without a description, so a described frame such asID3v1 Commentis still read afterwards, as before; for Vorbis""leaves one empty field), and any other value replaces the list. An emptyMOVEMENT,ORIGINALDATE, APEYear, or ID3MVNMno longer hides a filled fallback, and aTDORorTORYwithout a date no longer hides the other frame.CopyToreads every source value first, then writes. It replaces the target's list with the source value, even when that equals the target's first value. A list (performers, album artists, composers, genres, sort and role lists) the target already holds is left as it is; withExtendedthe artist and genre travel in those lists, so only aBasiccopy writes a single name over a list. When the source and target read from a common tag (t.CopyTo (t),mp3.Tag.CopyTo (mp3.Id3v2Tag),mp3.Tag.CopyTo (mp3.Tag)though each read is a new view,flac.Tag.CopyTo (flac.VorbisComment),aiff.Tag.CopyTo (aiff.Id3v2Tag)), every value the target already shows is skipped, so only values it lacks arrive. An empty source value still clears the field, as= ""does, so through a view it also clears what the view showed from another tag (an ID3v1 title, an AIFFNAMEchunk). In the other direction,mp3.Id3v2Tag.CopyTo (mp3.Tag)no longer rewrites ID3v1 with values the combined view already shows from ID3v2. A fallback field of its own beside a value equal to the copied one stays (VorbisORIGINALYEAR, APEDate, ID3v2.3TDORbesideTORY). Pictures are outside these rules, as before: a non-empty source picture list replaces the target's.Vorbis and APE movements follow MusicBrainz Picard's tag mapping: the name is
MOVEMENTNAME, the numberMOVEMENT(MOVEMENTNUMBERis still read first and kept in step). New names and numbers are written to those keys. AMOVEMENTthat is not a number still reads as the name when there is noMOVEMENTNAME. Clearing one half never changes how the other half reads, and a copy from a Picard FLAC no longer writes "2" overMVNM.Fixes #128