From 860406eb98b5c09397c3e297256f936ffb45dbfc Mon Sep 17 00:00:00 2001 From: EvilGiven Date: Sat, 27 Jun 2026 03:28:50 +0800 Subject: [PATCH] Fix XM save path to skip sample data after sample headers (#1369) XM saving failed for files with samples because the save logic only advanced past sample headers and did not skip the sample data, causing the next instrument to be written at the wrong position. --- taglib/xm/xmfile.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/taglib/xm/xmfile.cpp b/taglib/xm/xmfile.cpp index c4e0388d..6a3396d6 100644 --- a/taglib/xm/xmfile.cpp +++ b/taglib/xm/xmfile.cpp @@ -457,6 +457,7 @@ bool XM::File::save() } unsigned long sampleHeaderSize = 0; + unsigned long sampleDataSize = 0; if(sampleCount > 0) { seek(pos + 29); if(instrumentHeaderSize < 33U || !readU32L(sampleHeaderSize)) @@ -468,9 +469,12 @@ bool XM::File::save() for(unsigned short j = 0; j < sampleCount; ++ j) { if(sampleHeaderSize > 4U) { seek(pos); - if(unsigned long sampleLength = 0; !readU32L(sampleLength)) + unsigned long sampleLength = 0; + if(!readU32L(sampleLength)) return false; + sampleDataSize += sampleLength; + if(sampleHeaderSize > 18U) { seek(pos + 18); const auto sz = std::min(sampleHeaderSize - 18, 22UL); @@ -482,6 +486,8 @@ bool XM::File::save() } pos += sampleHeaderSize; } + + pos += sampleDataSize; } return true;