From e5a1ee2ac3cc729dcb5ac0337766c3f8bf6a49c4 Mon Sep 17 00:00:00 2001 From: zarzet Date: Sat, 11 Jul 2026 12:45:20 +0700 Subject: [PATCH] fix(metadata): shift stco/co64 chunk offsets when the ilst resizes writeM4AFreeformTags changed the ilst size without updating chunk offsets, which broke playback for faststart files (moov before mdat) after any ISRC/label/ReplayGain write. Reuses the AC-4 path's shiftChunkOffsets. --- go_backend/metadata.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/go_backend/metadata.go b/go_backend/metadata.go index d809238c..d61fc2fd 100644 --- a/go_backend/metadata.go +++ b/go_backend/metadata.go @@ -1676,6 +1676,14 @@ func writeM4AFreeformTags(filePath string, remove map[string]struct{}, tags []m4 if err := writeAtomSize(updated, path.moov, path.moov.size+delta); err != nil { return err } + // Keep sample pointers valid when moov precedes mdat: every stco/co64 + // entry at or beyond the resized ilst must shift with it. + if delta != 0 { + if moov, ok := findChildMP4(updated, 0, int64(len(updated)), "moov"); ok { + shiftChunkOffsets(updated, moov, path.ilst.offset, delta) + } + } + // Release the read handle before replacing the file (required on Windows). f.Close() return writeFileAtomic(filePath, updated, 0o644)