stream_decoder: fix integer underflow due to malformed wasted_bits
authorMax Kellermann <max@duempel.org>
Fri, 8 Jul 2016 19:29:41 +0000 (21:29 +0200)
committerErik de Castro Lopo <erikd@mega-nerd.com>
Sat, 9 Jul 2016 22:19:26 +0000 (08:19 +1000)
commit9949ce15f66d1312e7f0692298cfe8087488330b
tree4574c34fb643f2da2086afa9e90551bd51cb99f0
parent0a49fe7788ecab32a1238ecd45308afbbb580bec
stream_decoder: fix integer underflow due to malformed wasted_bits

It is pretty easy for a malformed FLAC file to underflow the "bps"
variable.  In the debug build, this results in an assertion failure in
FLAC__bitreader_read_raw_uint32():

    FLAC__ASSERT(bits <= 32);

In non-debug builds, this simply makes
FLAC__bitreader_read_raw_uint32() fail because
bitreader_read_from_client_() doesn't find enough buffer space for
2**32-1 bits.  But since the failing FLAC_ASSERT() is reasonable, this
should be caught in the FLAC__bitreader_read_raw_uint32() caller.

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
Closes: https://github.com/xiph/flac/pull/13
src/libFLAC/stream_decoder.c