From 52c2660c26beaaccf903759c18bb758e9f18a470 Mon Sep 17 00:00:00 2001 From: Martin Storsjo Date: Thu, 3 Aug 2017 13:47:15 +0300 Subject: [PATCH] Make sure at least one bit exists before reading further in FDKreadBit Fixes: 2709/clusterfuzz-testcase-minimized-6160249369133056 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg --- libFDK/include/FDK_bitstream.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libFDK/include/FDK_bitstream.h b/libFDK/include/FDK_bitstream.h index d47a750..19bc864 100644 --- a/libFDK/include/FDK_bitstream.h +++ b/libFDK/include/FDK_bitstream.h @@ -277,11 +277,15 @@ FDK_INLINE UINT FDKreadBit(HANDLE_FDK_BITSTREAM hBitStream) hBitStream->CacheWord = FDK_get32 (&hBitStream->hBitBuf); hBitStream->BitsInCache = CACHE_BITS; } - else + else if (validBits > 0) { hBitStream->CacheWord = FDK_get (&hBitStream->hBitBuf,validBits); hBitStream->BitsInCache = validBits; } + else + { + return 0; + } } hBitStream->BitsInCache--;