From 8147ee7ea214195bddab403840c95d4c748bfedc Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Sun, 25 Aug 2019 17:50:36 +1000 Subject: [PATCH] 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 --- src/libFLAC/bitreader.c | 6 ++++-- 1 file 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;