fix(library): a UTF-16 tag frame with a stray trailing zero no longer hides the whole file (#8060)
release / go (push) Successful in 2m4s
release / web (push) Successful in 1m21s
release / govulncheck (push) Successful in 20s
release / integration (push) Successful in 4m9s
release / android (push) Successful in 4m28s
release / Build signed APK (push) Successful in 4m56s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 14s
release / Verify release artifacts (tag releases only) (push) Skipped

Some taggers end a UTF-16 text frame with a two-byte terminator and then
one more zero byte, so the frame holds an odd number of bytes.
dhowden/tag refuses the whole tag when it meets one, and the scanner
then skipped the file: 61 tracks on dev (whole albums from one tagger,
with a genre or year frame written this way) never reached the library.

internal/tagread.ReadFrom reads with dhowden/tag first. When that fails
on an ID3v2.3/2.4 tag, it rebuilds the tag in memory with the stray
byte trimmed from each such frame and reads it again. Anything else
still fails with dhowden/tag's own error. The scanner, both MBID
backfills, embedded cover art and Subsonic lyrics all read through it.

The ID3v2 primitives (syncsafe and frame sizes, the extended header,
unsynchronisation) move from library/id3v2genre.go into tagread, so the
genre reader and the repair share one copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-26 14:05:55 -05:00
co-authored by Claude Opus 5.5
parent 17a9052acb
commit c9e058b3c9
9 changed files with 334 additions and 95 deletions
+3 -3
View File
@@ -6,11 +6,11 @@ import (
"log/slog"
"os"
"github.com/dhowden/tag"
"github.com/jackc/pgx/v5/pgxpool"
"git.fabledsword.com/bvandeusen/minstrel/internal/db"
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
"git.fabledsword.com/bvandeusen/minstrel/internal/tagread"
)
// BackfillMBIDsResult tallies what the one-shot worker did.
@@ -147,7 +147,7 @@ func readMBIDsForFile(path string, logger *slog.Logger) (albumMBID, artistMBID s
}
defer func() { _ = f.Close() }()
meta, err := tag.ReadFrom(f)
meta, err := tagread.ReadFrom(f)
if err != nil {
logger.Warn("mbid backfill: tag read failed", "path", path, "err", err)
return "", ""
@@ -241,7 +241,7 @@ func readRecordingMBIDForFile(path string, logger *slog.Logger) string {
}
defer func() { _ = f.Close() }()
meta, err := tag.ReadFrom(f)
meta, err := tagread.ReadFrom(f)
if err != nil {
logger.Warn("track mbid backfill: tag read failed", "path", path, "err", err)
return ""