From 71516df65173ce3c865141ed8bff6df0caa90584 Mon Sep 17 00:00:00 2001 From: Caleb Allen Date: Thu, 26 Mar 2026 15:05:13 -0400 Subject: [PATCH] fix: strip null bytes from ID3v2 TXXX/UFID tag values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The dhowden/tag library's Comm.Text and UFID.Identifier fields include trailing null bytes from the C-style strings in the ID3v2 binary format. strings.TrimSpace doesn't strip \x00, so MBIDs stored from MP3 files had invisible null bytes appended. This caused WHERE mbid = ? queries to fail — the stored value 'uuid\x00' didn't match the clean 'uuid' from search results. FLAC files (Vorbis comments with plain strings) were unaffected. Fix: use strings.TrimRight with explicit \x00 in the cutset. Requires a full rescan to fix existing corrupted MBIDs. --- backend/metadata/tags.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/metadata/tags.go b/backend/metadata/tags.go index 6250ca2..034e636 100644 --- a/backend/metadata/tags.go +++ b/backend/metadata/tags.go @@ -148,13 +148,14 @@ func extractMBIDs(raw map[string]interface{}, meta *TrackMetadata) { case *tag.Comm: // ID3v2 TXXX frames — Description is the tag name. if val != nil && val.Description != "" { - normalized[strings.ToLower(val.Description)] = strings.TrimSpace(val.Text) + text := strings.TrimRight(val.Text, "\x00 \t\n\r") + normalized[strings.ToLower(val.Description)] = text } case *tag.UFID: // ID3v2 UFID frame — MusicBrainz recording ID. if val != nil && val.Provider == "http://musicbrainz.org" { - meta.RecordingMBID = strings.TrimSpace(string(val.Identifier)) + meta.RecordingMBID = strings.TrimRight(string(val.Identifier), "\x00 \t\n\r") } } }