Skip to content

Commit 91461f5

Browse files
committed
Fix DFF test builder to use IFF 2-byte alignment
The DFF test builder was incorrectly using 8-byte chunk alignment, but the IFF (Interchange File Format) specification requires 2-byte alignment for odd-sized chunks. This caused DFF parsing tests to fail because the parser couldn't find the DSD audio data chunk at the expected offset. Changes: - Fix DITI/DIAR chunk size calculation to account for 2-byte alignment - Replace 8-byte padding loops with 2-byte alignment checks - Add comments explaining the IFF alignment requirement
1 parent 90cd311 commit 91461f5

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

tests/TagLibSharp2.Tests/TestBuilders.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4056,9 +4056,9 @@ public static byte[] CreateWithMetadata (
40564056
var diarChunkSize = artistBytes.Length > 0 ? 12 + 4 + artistBytes.Length : 0;
40574057
var dsdChunkSize = 12 + 4096;
40584058

4059-
// Add padding for alignment
4060-
ditiChunkSize = (ditiChunkSize + 7) & ~7;
4061-
diarChunkSize = (diarChunkSize + 7) & ~7;
4059+
// IFF uses 2-byte alignment for odd-sized chunks
4060+
if (ditiChunkSize % 2 != 0) ditiChunkSize++;
4061+
if (diarChunkSize % 2 != 0) diarChunkSize++;
40624062
var formSize = 4 + fverChunkSize + propChunkSize + ditiChunkSize + diarChunkSize + dsdChunkSize;
40634063

40644064
// FRM8 container
@@ -4087,16 +4087,17 @@ public static byte[] CreateWithMetadata (
40874087
builder.AddUInt64BE ((ulong)cmprChunkDataSize);
40884088
builder.AddStringLatin1 ("DSD ");
40894089
builder.Add ((byte)0);
4090-
while (builder.Length % 8 != 0)
4091-
builder.Add ((byte)0);
4090+
// cmprChunkDataSize=5 is odd, add 1 padding byte per IFF 2-byte alignment
4091+
builder.Add ((byte)0);
40924092

40934093
// DITI chunk (title)
40944094
if (titleBytes.Length > 0) {
40954095
builder.AddStringLatin1 ("DITI");
40964096
builder.AddUInt64BE ((ulong)(4 + titleBytes.Length));
40974097
builder.AddUInt32BE ((uint)titleBytes.Length);
40984098
builder.Add (titleBytes);
4099-
while (builder.Length % 8 != 0)
4099+
// IFF 2-byte alignment: add padding if chunk data size is odd
4100+
if ((4 + titleBytes.Length) % 2 != 0)
41004101
builder.Add ((byte)0);
41014102
}
41024103

@@ -4106,7 +4107,8 @@ public static byte[] CreateWithMetadata (
41064107
builder.AddUInt64BE ((ulong)(4 + artistBytes.Length));
41074108
builder.AddUInt32BE ((uint)artistBytes.Length);
41084109
builder.Add (artistBytes);
4109-
while (builder.Length % 8 != 0)
4110+
// IFF 2-byte alignment: add padding if chunk data size is odd
4111+
if ((4 + artistBytes.Length) % 2 != 0)
41104112
builder.Add ((byte)0);
41114113
}
41124114

0 commit comments

Comments
 (0)