jstrait / wavefile

A Ruby gem for reading and writing sound files in Wave format (*.wav)
https://wavefilegem.com
MIT License
208 stars 24 forks source link

`Reader` instances can be created for WAVE_FORMAT_EXTENSIBLE files that have an incomplete/missing format chunk extension #34

Closed jstrait closed 1 year ago

jstrait commented 3 years ago

When a fmt chunk has the format code 65534 (i.e. WAVE_FORMAT_EXTENSIBLE) it is required to have a chunk extension of 22 bytes containing 3 fields. These fields, especially the final 16 byte "audio format GUID" field, are required in order to correctly read the file's sample data, and don't have sensible default values.

In v1.1.1 of the gem a Reader instance can be created, without any error being raised, for some WAVE_FORMAT_EXTENSIBLE files in which the fmt chunk has a missing/truncated extension. The readable_format? field on the Reader instance will be correctly set to false, so no sample data will be able to be read out of it. However, the object attached to format and native_format will contain invalid values (i.e. either nil or "") for the missing extension fields.

It seems like a bug that Reader instances can be created from files like this. These are malformed files, and some of the information shown in the objects returned by format and native_format will not necessarily be meaningful/accurate. It seems like better behavior would be to instead raise an InvalidFormatError when trying to read this type of file, and not allow a Reader instance to be created.

jstrait commented 1 year ago

This is now fixed in v1.1.2, so closing this issue.