diff options
author | Erik de Castro Lopo <erikd@mega-nerd.com> | 2019-08-25 17:50:36 +1000 |
---|---|---|
committer | Erik de Castro Lopo <erikd@mega-nerd.com> | 2019-09-16 06:18:07 +1000 |
commit | 8147ee7ea214195bddab403840c95d4c748bfedc (patch) | |
tree | 96e1c5a942c732de10af00649018417d2dcc7ce8 | |
parent | 09f47c00e18a77390acfc2e725564542756effaf (diff) | |
download | flac-8147ee7ea214195bddab403840c95d4c748bfedc.tar.gz |
libFLAC/bitreader.c: Fix shift invoking undefined behaviour
Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=16464
Testcase: fuzzer_decoder-5663276452544512
-rw-r--r-- | src/libFLAC/bitreader.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/libFLAC/bitreader.c b/src/libFLAC/bitreader.c index 62e11991..5e4b5918 100644 --- a/src/libFLAC/bitreader.c +++ b/src/libFLAC/bitreader.c @@ -119,8 +119,10 @@ static inline void crc16_update_word_(FLAC__BitReader *br, brword word) { register uint32_t crc = br->read_crc16; - for( ; br->crc16_align < FLAC__BITS_PER_WORD; br->crc16_align += 8) - crc = FLAC__CRC16_UPDATE((uint32_t)((word >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), crc); + for ( ; br->crc16_align < FLAC__BITS_PER_WORD ; br->crc16_align += 8) { + uint32_t shift = FLAC__BITS_PER_WORD - 8 - br->crc16_align ; + crc = FLAC__CRC16_UPDATE ((uint32_t) (shift < FLAC__BITS_PER_WORD ? (word >> shift) & 0xff : 0), crc); + } br->read_crc16 = crc; br->crc16_align = 0; |