NativeInstruments / ni-media

NI Media is a C++ library for reading and writing audio streams.
MIT License
235 stars 34 forks source link

Use 32bit integer to enforce byte alignment while parsing wav sources. #63

Closed wro-ableton closed 9 months ago

wro-ableton commented 9 months ago

This changes the binary mask used to discard the 1-bit while seeking through wav files from 0xfffffe (which casted to 32bit is 0x00fffffe) to 0xfffffffe. This prevents a serious issues which may arise when parsing large files. This mask is used in addition with a offset of 1 to pad the chunk size to even numbers.

Without this adjustment, files which force the parser to seek beyond this limit would end up seeking to a quasi-random position of the file, try to read chunk ID and size from there and continue. This, leads to the parser basically jumping randomly within the file, interpreting random data as chunk size and chunk id.

One could argue that a 64 bit integer should be used for this operation? Though wav itself uses 32bit integers to determine chunk sizes.

ni-mheppner commented 9 months ago

Superseded by #65. Closing. Thanks a lot, @wro-ableton, for providing the fix!