You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ID3v2/MPEG: write re-probe rejects large-gap files (no write-side max_junk override); duplicate COMM/USLT frames dropped on read #668
Probe::new carries no ParseOptions, so guess_file_type uses ParseOptions::DEFAULT_MAX_JUNK_BYTES (1024). For an ID3v2-prefixed MPEG file, guess_inner skips the tag block and then check_mpeg_or_aac searches for a frame sync only within take(1024) bytes measured from the end of the ID3v2 tag (src/probe.rs, MaybePrecededById3 → check_mpeg_or_aac). When the gap between the tag end and the first frame sync exceeds 1024 bytes, the guess returns None and the write fails with UnknownFormat — even though the very same file reads fine (the read path's frame-sync search is unbounded).
WriteOptions does not expose max_junk_bytes (nor any ParseOptions), so there is no write-side override. The file is effectively read-only to lofty through no fault of its tags.
Repro shape: an MP3 with [ID3v2.3 tag][~1044 bytes padding/junk][first MPEG frame]. ~1.3% of a real 6,869-file library (90 files) carries exactly this layout (a uniform 1044-byte gap — an encoder/iTunes artifact).
Request (either):
thread a max_junk_bytes (or full ParseOptions) through WriteOptions into the write-path probe; or
have save_to/write_to reuse the file type already determined when the file was read, instead of blind-re-probing on write.
(2) Reading two distinct same-key COMM/USLT frames silently drops one
parse_id3v2 inserts each parsed frame into the tag:
Id3v2Tag::insert replaces any frame "of the same id (or description!)" (src/id3/v2/tag.rs:331). For COMM/USLT, the de-dup key includes language + description. The read loop has a guard that restores a non-empty frame when an empty one would replace it — but when both frames are non-empty and share (id, language, description), the second silently replaces the first; only a log::warn is emitted. There is no API to retain both. For USLT (lyrics) and COMM (comments), this is real content loss on a plain read→write round-trip.
Request: a way to preserve duplicate text frames on read (or, at minimum, elevate this above a silent warn so callers can detect and handle it).
Happy to provide sample files / a minimal repro for either.
Hi @John-CalmVise. Please make separate issues in the future.
Issue 1
Yeah, I have a bunch of TODOs scattered around to make ParseOptions available in WriteOptions. I'll try to finally get that in the next release.
have save_to/write_to reuse the file type already determined when the file was read, instead of blind-re-probing on write.
A re-probe is necessary for any write. Tags are independent of the files they were read from, so you can take an ID3v2 tag from an MP3 and write it to a WAV, for example. Once a tag is read, no assumption is made about its destination.
Issue 2
This is expected behavior. It's a spec violation to have multiple COMM/USLT frames with the same language and description. No app should be relying on that behavior. Do you have a use case?
For USLT (lyrics) and COMM (comments), this is real content loss on a plain read→write round-trip.
Technically, but Lofty shouldn't write non-spec-compliant tags in any case.
In that vein, Lofty actually does quite a few transformations on parse that may alter/shift around content, see ParseOptions::implicit_conversions(). That doesn't apply here, just wanted to point out that a "plain read->write round-trip" may not produce the exact same tag in other cases.
Thanks, this is really helpful — and noted on separate issues, I'll split them next time.
Issue 1: That makes sense on the re-probe — tags being destination-independent is a fair design call, so I won't expect the reuse-the-read-type route. The ParseOptions-in-WriteOptions plan is exactly what we need: being able to pass max_junk_bytes (or full ParseOptions) through to the write probe would let save_to succeed on the files we currently can't write — the ones whose first MPEG frame sits >1024 bytes past the ID3v2 tag, which read fine but fail the write re-probe. That'd let us retire a hand-rolled workaround on our end, so we'll watch for it in the next release. No rush — really appreciate you slotting it in.
Issue 2 — the use case you asked about: it's not that we (or any app) rely on duplicate same-language COMM/USLT frames — agreed those are a spec violation and shouldn't be relied on. The concern is narrower: when a file a user already has happens to carry two same-language frames with distinct content (e.g. two USLT lyrics or two COMM comments), a routine metadata write silently collapses them to one — so a write the user requested for an unrelated reason quietly destroys pre-existing content in their file. We've handled it on our side by detecting that collision and declining the write (leaving the file untouched rather than dropping a frame), so it's not blocking us — I mainly wanted it on your radar as a silent-content-loss footgun on plain round-trips. And good to know about implicit_conversions() doing other transforms on parse; that's useful context.
@John-CalmVise For issue 2 do you have any extra context? Is this something you've encountered specifically with COMM/USLT or are you looking to retain all duplicate frames? And do you know the source of those files?
Is it COMM/USLT specifically, or all duplicate frames? COMM/USLT specifically. The concern is narrowly the content-bearing text frames — lyrics (USLT) and comments (COMM) — where a dropped frame is lost content, not general retention of arbitrary duplicate frames. I'm not looking to preserve duplicates broadly.
Source of the files? iTunes/Apple-encoded MP3s from a real personal library — the same provenance as the files in issue 1 (the uniform padding-gap cohort, an iTunes/encoder artifact). So it's a widespread real-world encoder rather than a synthetic or hand-crafted edge case. I'm glad to put together a minimal repro file if that's useful.
Retain all duplicates, or just detect? Just detect — and to be clear up front, I'm not asking for retain-both. I agree with your position: these tags are spec-violating, and lofty is right not to write non-compliant frames. So retention isn't the ask.
The only gap that bites a caller is detectability. Right now the read-time drop surfaces as a silent log::warn, so a caller has no programmatic way to know a frame was dropped — a plain read→write round-trip silently loses lyrics/comments with no signal to act on. If that condition were surfaced so a caller could catch it (an error, a flag on the result, anything programmatic — not a log line), that's entirely sufficient.
For context on why detection alone is enough for us: in our own write path we already take the detect-and-refuse approach — when a repair we make would manufacture a same-key collision, we detect it against lofty's parsed model, skip the mutation, and leave the file flagged as write-blocked rather than drop anything. If lofty's read-time drop were similarly catchable, we'd handle it the same way (flag the file, refuse the round-trip). No retain-both API needed.
iTunes/Apple-encoded MP3s from a real personal library
Can you be more specific? Under what conditions is iTunes producing duplicate COMM/USLT and is it a common issue in your library? iTunes is no stranger to bugs but this isn't one that I've heard of, so I'm interested to learn more.
Good question — and having actually dug into it, I should be straight with you: I can't cleanly reproduce it from my own library.
I went back through the whole thing (~6,900 files) looking for genuine same-language, same-description duplicate COMM/USLT frames and didn't find a single one. The only same-description duplicates I have differ by language — which, as I understand your dedup key (language + description), you'd correctly keep, not drop. So this turned out to be a structural concern about how some of these 25-plus-year-old files were tagged and re-tagged over the years, more than an actual cohort I can hand you.
I'd treat the detectability note as take-it-or-leave-it rather than something worth chasing. Thanks for the thoughtful questions — and sorry for the slight wild goose chase.
Correction, and an honest one: I was wrong that I couldn't reproduce it — I'd been checking files my own tooling had already rewritten. In a clean, untouched copy of my library, 48 files genuinely carry duplicated frames: the entire ID3v2 tag is written ~twice. So the condition is real, and those "Replaced frame with ID…" warnings were firing on exactly these files.
Rather than ship copyrighted audio, here are verbatim frame dumps of two real examples (binary frames render as byte-counts — no audio or image data):
The whole tag is doubled (duplicate TPE1/TALB/TIT2/TRCK/TYER), with two identical emptyCOMM frames (lang [0,0,0]) and two APIC images. This is the file your COMM "Replaced frame with ID" warning fires on — both COMM are empty, so nothing is lost.
Two USLT (lyrics) frames with different language codes ([88,88,88] vs [101,110,103]), so you correctly keep both — no loss; plus a single real comment ("5 Stars") where I'd rated the track.
So your instinct holds up: genuine duplicated/empty frames — the residue of ~25 years of taggers writing over each other — but no actual text content is lost. The duplicate COMM are empty and the duplicate USLT differ by language. No content-loss bug to chase. Thanks for your patience, and apologies for the earlier wrong call.
Interesting, if Lofty encounters multiple ID3v2 tags in the same file it merges them together. Do you know if that's the case in example 1 or did the encoder genuinely write duplicate frames to the same tag? I can check if you're not sure, you can email files to serial AT [domain on my profile]
Good question — I dug into the raw bytes and it's the latter: a single ID3v2 tag with genuinely duplicated frames, not multiple tags being merged.
There's exactly one ID3 header in the file (offset 0, v2.3, tag_size=330085) and no second ID3v2 tag anywhere in it. Inside that one tag the core metadata block is physically written ~twice — the frame-id sequence runs:
Activity
Serial-ATA commentedon Jun 23, 2026
Hi @John-CalmVise. Please make separate issues in the future.
Issue 1
Yeah, I have a bunch of TODOs scattered around to make
ParseOptionsavailable inWriteOptions. I'll try to finally get that in the next release.A re-probe is necessary for any write. Tags are independent of the files they were read from, so you can take an ID3v2 tag from an MP3 and write it to a WAV, for example. Once a tag is read, no assumption is made about its destination.
Issue 2
This is expected behavior. It's a spec violation to have multiple
COMM/USLTframes with the same language and description. No app should be relying on that behavior. Do you have a use case?Technically, but Lofty shouldn't write non-spec-compliant tags in any case.
In that vein, Lofty actually does quite a few transformations on parse that may alter/shift around content, see ParseOptions::implicit_conversions(). That doesn't apply here, just wanted to point out that a "plain read->write round-trip" may not produce the exact same tag in other cases.
John-CalmVise commentedon Jun 24, 2026
Thanks, this is really helpful — and noted on separate issues, I'll split them next time.
Issue 1: That makes sense on the re-probe — tags being destination-independent is a fair design call, so I won't expect the reuse-the-read-type route. The
ParseOptions-in-WriteOptionsplan is exactly what we need: being able to passmax_junk_bytes(or fullParseOptions) through to the write probe would letsave_tosucceed on the files we currently can't write — the ones whose first MPEG frame sits >1024 bytes past the ID3v2 tag, which read fine but fail the write re-probe. That'd let us retire a hand-rolled workaround on our end, so we'll watch for it in the next release. No rush — really appreciate you slotting it in.Issue 2 — the use case you asked about: it's not that we (or any app) rely on duplicate same-language
COMM/USLTframes — agreed those are a spec violation and shouldn't be relied on. The concern is narrower: when a file a user already has happens to carry two same-language frames with distinct content (e.g. twoUSLTlyrics or twoCOMMcomments), a routine metadata write silently collapses them to one — so a write the user requested for an unrelated reason quietly destroys pre-existing content in their file. We've handled it on our side by detecting that collision and declining the write (leaving the file untouched rather than dropping a frame), so it's not blocking us — I mainly wanted it on your radar as a silent-content-loss footgun on plain round-trips. And good to know aboutimplicit_conversions()doing other transforms on parse; that's useful context.Thanks again for the quick and thorough response.
Serial-ATA commentedon Jun 24, 2026
@John-CalmVise For issue 2 do you have any extra context? Is this something you've encountered specifically with
COMM/USLTor are you looking to retain all duplicate frames? And do you know the source of those files?John-CalmVise commentedon Jun 25, 2026
Thanks @Serial-ATA — happy to give the context.
Is it COMM/USLT specifically, or all duplicate frames? COMM/USLT specifically. The concern is narrowly the content-bearing text frames — lyrics (USLT) and comments (COMM) — where a dropped frame is lost content, not general retention of arbitrary duplicate frames. I'm not looking to preserve duplicates broadly.
Source of the files? iTunes/Apple-encoded MP3s from a real personal library — the same provenance as the files in issue 1 (the uniform padding-gap cohort, an iTunes/encoder artifact). So it's a widespread real-world encoder rather than a synthetic or hand-crafted edge case. I'm glad to put together a minimal repro file if that's useful.
Retain all duplicates, or just detect? Just detect — and to be clear up front, I'm not asking for retain-both. I agree with your position: these tags are spec-violating, and lofty is right not to write non-compliant frames. So retention isn't the ask.
The only gap that bites a caller is detectability. Right now the read-time drop surfaces as a silent
log::warn, so a caller has no programmatic way to know a frame was dropped — a plain read→write round-trip silently loses lyrics/comments with no signal to act on. If that condition were surfaced so a caller could catch it (an error, a flag on the result, anything programmatic — not a log line), that's entirely sufficient.For context on why detection alone is enough for us: in our own write path we already take the detect-and-refuse approach — when a repair we make would manufacture a same-key collision, we detect it against lofty's parsed model, skip the mutation, and leave the file flagged as write-blocked rather than drop anything. If lofty's read-time drop were similarly catchable, we'd handle it the same way (flag the file, refuse the round-trip). No retain-both API needed.
Thanks again for taking the time on this.
Serial-ATA commentedon Jun 25, 2026
Can you be more specific? Under what conditions is iTunes producing duplicate COMM/USLT and is it a common issue in your library? iTunes is no stranger to bugs but this isn't one that I've heard of, so I'm interested to learn more.
John-CalmVise commentedon Jun 25, 2026
Good question — and having actually dug into it, I should be straight with you: I can't cleanly reproduce it from my own library.
I went back through the whole thing (~6,900 files) looking for genuine same-language, same-description duplicate COMM/USLT frames and didn't find a single one. The only same-description duplicates I have differ by language — which, as I understand your dedup key (language + description), you'd correctly keep, not drop. So this turned out to be a structural concern about how some of these 25-plus-year-old files were tagged and re-tagged over the years, more than an actual cohort I can hand you.
I'd treat the detectability note as take-it-or-leave-it rather than something worth chasing. Thanks for the thoughtful questions — and sorry for the slight wild goose chase.
John-CalmVise commentedon Jun 25, 2026
Correction, and an honest one: I was wrong that I couldn't reproduce it — I'd been checking files my own tooling had already rewritten. In a clean, untouched copy of my library, 48 files genuinely carry duplicated frames: the entire ID3v2 tag is written ~twice. So the condition is real, and those "Replaced frame with ID…" warnings were firing on exactly these files.
Rather than ship copyrighted audio, here are verbatim frame dumps of two real examples (binary frames render as byte-counts — no audio or image data):
Example 1 — unrated track (the
COMM-drop case):The whole tag is doubled (duplicate
TPE1/TALB/TIT2/TRCK/TYER), with two identical emptyCOMMframes (lang[0,0,0]) and twoAPICimages. This is the file yourCOMM"Replaced frame with ID" warning fires on — bothCOMMare empty, so nothing is lost.Example 2 — a track I'd rated (the
USLTcase):Two
USLT(lyrics) frames with different language codes ([88,88,88]vs[101,110,103]), so you correctly keep both — no loss; plus a single real comment ("5 Stars") where I'd rated the track.So your instinct holds up: genuine duplicated/empty frames — the residue of ~25 years of taggers writing over each other — but no actual text content is lost. The duplicate
COMMare empty and the duplicateUSLTdiffer by language. No content-loss bug to chase. Thanks for your patience, and apologies for the earlier wrong call.Serial-ATA commentedon Jun 25, 2026
Interesting, if Lofty encounters multiple ID3v2 tags in the same file it merges them together. Do you know if that's the case in example 1 or did the encoder genuinely write duplicate frames to the same tag? I can check if you're not sure, you can email files to
serial AT [domain on my profile]John-CalmVise commentedon Jun 25, 2026
Good question — I dug into the raw bytes and it's the latter: a single ID3v2 tag with genuinely duplicated frames, not multiple tags being merged.
There's exactly one
ID3header in the file (offset 0, v2.3,tag_size=330085) and no second ID3v2 tag anywhere in it. Inside that one tag the core metadata block is physically written ~twice — the frame-id sequence runs:So whatever tagged these over the years (iTunes/MusicMatch passes) wrote the duplicates straight into the single tag — no merge involved.
I'll email you the two example files so you can confirm directly — thanks for offering to take a look.