JUCE 9: Some wav files don't load anymore

Received reports by two users shortly ofter we updated our plugin to juce 9. Some wav files don’t load anymore.

Edit:
Example wav file:
SomeWave.wav.zip (12.1 KB)

The problem is related to following change:

where the code is more restrictive about malformed chunks instead of just ignoring them, directly returns.

It would be great to get the old behaviour back where we continue the import also when a chunk is malformed, instead of skipping the whole loading process.

It looks like is common that some DAW’s and tools write malformed wav file chunks and people can’t read them anymore after this change. Edit: Such malformed wav files can also be found on older sample CD’s.

Edit: Other audio tools can load this files. I think we should also be able to do this.

Something like this restores the behaviour and fixes the problem:

if (numBytesAvailable >= 0 && snappedLength > numBytesAvailable)
{
    // Malformed chunk, its length is longer than the stream itself                                                                
    // return;                                                                                                                        
                                                                                      
    snappedLength = numBytesAvailable;
    length = (uint32) numBytesAvailable;                                                                                  
}
3 Likes

I didn’t look at the diff but if the chunk has a length that is too long, then you wouldn’t know how many bytes to skip. So how do you skip such chunks?

We have numBytesAvailable. I think it would be a good idea to read what’s available.

Yeah if that is the data chunk I’d agree.

Otherwise we may ignore it and go to the next chunk

My point was that if a chunk has the wrong size, you won’t know where the next chunk begins. :wink:

Regardless, I was thinking of updating to JUCE 9 but the product I’m working on requires loading WAV files so I’d better wait…

Thats true :slight_smile: The problem is, that JUCE checks every chunk, even those that are empty or not relevant and skips the whole import when something is wrong.

I have attached a file that does not load with the current JUCE 9 and worked before the mentioned commit above:
SomeWave.wav.zip (12.1 KB)

When applying the fix above and continue the import also after a wrong chunk, then it imports again. All other wave editors I have tested can open this file.

Thank you for sharing this.

The shared wav file seems to be missing the byte padding, but the data chunk itself is correct. Given how other programs read such files, we will look into doing the same.

2 Likes

A fix is now out on develop.

3 Likes

Thanks for the fast patch.