Skip to content

Commit 90cd311

Browse files
committed
Fix Musepack SV8 Stream Header parsing
The parser was only skipping 1 byte before reading sample count, but per Musepack SV8 spec the Stream Header payload starts with: - 4 bytes: CRC32 - 1 byte: Stream version - Variable length: Sample count - Variable length: Beginning silence - 1 byte: Flags Updated parser to skip 5 bytes (CRC + version) before reading the variable-length sample count. Also fixed the local test helper to include the 4-byte CRC placeholder for consistency with TestBuilders.
1 parent c1ea975 commit 90cd311

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/TagLibSharp2/Musepack/MusepackFile.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,11 @@ private static void ParseSV8StreamHeader (ReadOnlySpan<byte> payload, MusepackFi
284284

285285
var offset = 0;
286286

287-
// Skip CRC/version byte
288-
if (offset >= payload.Length) return;
289-
offset++;
287+
// Skip CRC32 (4 bytes) + Stream version (1 byte)
288+
// Per Musepack SV8 spec, SH payload starts with these 5 bytes
289+
if (payload.Length < 5)
290+
return;
291+
offset += 5;
290292

291293
// Sample count (variable-length integer)
292294
var sampleCountResult = ReadVarInt (payload, offset);

tests/TagLibSharp2.Tests/Musepack/MusepackFileTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,9 @@ private static byte[] CreateSV8StreamHeaderPacket (int sampleRate, int channels,
746746
using var payloadMs = new MemoryStream ();
747747

748748
// SH payload:
749-
// [0] CRC (skip for test - 1 byte for version indicator)
749+
// [0-3] CRC32 placeholder (4 bytes)
750+
payloadMs.Write (new byte[4]);
751+
// [4] Stream version
750752
payloadMs.WriteByte (8); // Version 8
751753

752754
// Sample count as variable-length integer

0 commit comments

Comments
 (0)