Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: BUG: WAVE file tags result in wrong id3 chunk size (Read 1172 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

BUG: WAVE file tags result in wrong id3 chunk size

foobar2000 seems to have a subtle bug when adding tags to a WAVE file. When editing the tags for WAVE f2k will add both a INFO LIST and ID3 chunk to the WAVE file. But the size of the ID3 chunk seems to be one byte short.

Take the attached test.wav file without tags. I used f2k to add tags, the result is test-f2k-tagged.wav. If I print out the chunks of the file I get this:

RIFF: data_offset 8, data_size 14730, total_size 14738
fmt: data_offset 20, data_size 16, total_size 24
data: data_offset 44, data_size 14608, total_size 14616
LIST: data_offset 14660, data_size 24, total_size 32
id3: data_offset 14692, data_size 45, total_size 53

The offsets are all correct. The RIFF chunk's total size is 14738 bytes, this equals the size of the file.

But the id3 chunk  is strange. The offset + data size is 14737, one byte less then the total size. If you look at the file in a hex editor you will see there is a null byte at the end that is not part of the id3 chunk. It looks like the calculation of the id3 chunk length is one byte off.

Furthermore, if you remove the id3 chunk now with the given length this last stray byte is still present, but now directly after the LIST chunk (see test-f2k-tagged-id3-removed.wav). Such a file f2k can no longer tag, it reports it as a broken file.

Manually fixing this in a hex editor by reducing the RIFF chunk length by 1 and deleting the stray byte at the end of the file again results in a working file (test-f2k-tagged-id3-removed-fixed-length.wav).

EDIT: This was done with foobar2000 1.4.8. The issue is also discussed at https://github.com/quodlibet/mutagen/issues/392

Re: BUG: WAVE file tags result in wrong id3 chunk size

Reply #1
Don't forget that RIFF calls for all chunks to be aligned to multiples of two bytes, so if the length is odd, there will be one byte of padding. I guess it mishandles ID3 chunks?

Re: BUG: WAVE file tags result in wrong id3 chunk size

Reply #2
You are right. I had assumed the padding should be part of the chunk, but actually it isn't according to spec:

"chunkSize gives the size of the valid data in the chunk. It does not include the padding, the size of chunkID, or the size of chunkSize."

So no, the padding is extra, the size really indicates only the data itself. That means the behavior in f2k is actually correct.

 

Re: BUG: WAVE file tags result in wrong id3 chunk size

Reply #3
Not having fb2k 1.4.8 available right now, it looks correct at a first glance: As kode54 points out, RIFF chunks have to be word-aligned, the chunks size will not include the (possible) padding byte. I have to adjust the same thing in loudgain.

Oops, @phw was faster :-)