From 4e944af756ec44e73b78bbed84a01fa9d2dfa5f5 Mon Sep 17 00:00:00 2001 From: Martin Storsjo Date: Tue, 17 Nov 2020 12:15:20 +0200 Subject: [PATCH] Avoid undefined shifts in SBR calcCRC Fixes: 25404/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_LIBFDK_AAC_fuzzer-5397024709804032 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg --- libSBRdec/src/sbr_crc.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libSBRdec/src/sbr_crc.cpp b/libSBRdec/src/sbr_crc.cpp index ba0fd05..8a5282e 100644 --- a/libSBRdec/src/sbr_crc.cpp +++ b/libSBRdec/src/sbr_crc.cpp @@ -153,8 +153,10 @@ static int getCrc(HANDLE_FDK_BITSTREAM hBs, ULONG NrBits) { calcCRC(&CrcBuf, bValue, MAXCRCSTEP); } - bValue = FDKreadBits(hBs, CrcNrBitsRest); - calcCRC(&CrcBuf, bValue, CrcNrBitsRest); + if (CrcNrBitsRest > 0) { + bValue = FDKreadBits(hBs, CrcNrBitsRest); + calcCRC(&CrcBuf, bValue, CrcNrBitsRest); + } return (CrcBuf.crcState & SBR_CRC_RANGE); }