Skip to content

v1.1.2

Latest
Compare
Choose a tag to compare
@jstrait jstrait released this 30 Dec 21:50
· 102 commits to master since this release

This version fixes several edge case bugs related to reading a *.wav file's "fmt " chunk. In particular, reading a "fmt " chunk that has extra trailing bytes; reading a "fmt " chunk in WAVE_FORMAT_EXTENSIBLE format whose chunk extension is missing, incomplete, or has extra trailing bytes; and reading a "fmt " chunk whose chunk extension is too large to fit in the chunk. In short, some valid files that were previously rejected can now be read, and some invalid files are handled more properly.

The full details:

  • Bug Fix: Files that have extra bytes at the end of the "fmt " chunk can now be read.

    If the format code is 1, the "fmt " chunk has extra bytes if the chunk body size is greater than 16 bytes. Otherwise, "extra bytes" means the chunk contains bytes after the chunk extension (not including the required padding byte for an odd-sized chunk).

    Previously, attempting to open certain files like this via Reader.new would result in InvalidFormatError being raised with a misleading "Not a supported wave file. The format chunk extension is shorter than expected." message. This was misleading because if the format code is 1, the "fmt " chunk won't actually have a chunk extension, and for other format codes the chunk extension might actually be the expected size or larger. When reading a file like this, any extra data in the "fmt " chunk beyond what is expected based on the relevant format code will now be ignored.

    • There was a special case where a file like this could be opened correctly. If the format code was 1, and the value of bytes 16 and 17 (0-based), when interpreted as a 16-bit unsigned little-endian integer, happened to be the same as the number of subsequent bytes in the chunk, the file could be opened without issue. For example, if the "fmt " chunk size was 22, the format code was 1, and the value of bytes 16 and 17 was 4 (when interpreted as a 16-bit unsigned little-endian integer), the file could be opened correctly.
    • There was another special case where InvalidFormatError would be incorrectly raised, but the error message would be different (and also misleading). If the format code was 1, and there was exactly 1 extra byte in the "fmt " chunk (i.e. the chunk size was 17 bytes), the error message would be "Not a supported wave file. The format chunk is missing an expected extension." This was misleading because when the format code is 1, the "fmt " chunk doesn't have a chunk extension.
    • Thanks to @CromonMS for reporting this as an issue.
  • Bug Fix: Files in WAVE_FORMAT_EXTENSIBLE format with a missing or incomplete "fmt " chunk extension can no longer be opened using Reader.new.

    Previously, a Reader instance could be constructed for a file like this, but the relevant fields on the object returned by Reader#native_format would contain nil or "" values for these fields, and no sample data could be read from the file. Since files like this are missing required fields that don't necessarily have sensible default values, it seems like it shouldn't be possible to create a Reader instance from them. After this fix, attempting to do so will cause InvalidFormatError to be raised.

  • Bug Fix: Files in WAVE_FORMAT_EXTENSIBLE format that have extra bytes at the end of the "fmt " chunk extension can now be read.

    This is similar but different from the first bug above; that bug refers to extra bytes after the chunk extension, while this bug refers to extra bytes inside the chunk extension. A WAVE_FORMAT_EXTENSIBLE "fmt " chunk extension has extra bytes if it is larger than 22 bytes.

    Previously, a Reader instance could be constructed for a file like this, but Reader#native_format#sub_audio_format_guid would have an incorrect value, and sample data could not be read from the file. After this fix, this field will have the correct value, and if it is one of the supported values then sample data can be read. Any extra data at the end of the chunk extension will be ignored.

    Implicit in this scenario is that the "fmt " chunk has a stated size large enough to fit the oversized chunk extension. For cases where it doesn't, see the next bug fix below.

  • Bug Fix: More accurate message on the InvalidFormatError raised when reading a file whose "fmt " chunk extension is too large to fit in the chunk.

    The message will now correctly state that the chunk extension is too large, rather than "Not a supported wave file. The format chunk extension is shorter than expected.". As an example of what "too large" means, if a "fmt " chunk has a size of 50 bytes, then any chunk extension larger than 32 bytes will be too large and overflow out of the chunk, since a chunk extension's content always starts at byte 18 (0-based).