From 52c2660c26beaaccf903759c18bb758e9f18a470 Mon Sep 17 00:00:00 2001 From: Martin Storsjo Date: Thu, 3 Aug 2017 13:47:15 +0300 Subject: 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(-) (limited to 'libFDK') 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--; -- cgit v1.2.3 From 5891b75b311c8fb27706cc2128a49d10dc477dca Mon Sep 17 00:00:00 2001 From: Martin Storsjo Date: Tue, 6 Mar 2018 12:35:43 +0200 Subject: Fix warnings with MSVC about mismatch between signed and unsigned in a header --- libFDK/include/FDK_bitstream.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libFDK') diff --git a/libFDK/include/FDK_bitstream.h b/libFDK/include/FDK_bitstream.h index 19bc864..e75e570 100644 --- a/libFDK/include/FDK_bitstream.h +++ b/libFDK/include/FDK_bitstream.h @@ -245,7 +245,7 @@ FDK_INLINE UINT FDKreadBits(HANDLE_FDK_BITSTREAM hBitStream, if (hBitStream->BitsInCache <= numberOfBits) { - const UINT validBits = FDK_getValidBits (&hBitStream->hBitBuf) ; + const INT validBits = FDK_getValidBits (&hBitStream->hBitBuf) ; const INT freeBits = (CACHE_BITS-1) - hBitStream->BitsInCache ; const INT bitsToRead = (freeBits <= validBits) ? freeBits : validBits ; @@ -309,7 +309,7 @@ inline UINT FDKread2Bits(HANDLE_FDK_BITSTREAM hBitStream) UINT BitsInCache = hBitStream->BitsInCache; if (BitsInCache < 2) /* Comparison changed from 'less-equal' to 'less' */ { - const UINT validBits = FDK_getValidBits (&hBitStream->hBitBuf) ; + const INT validBits = FDK_getValidBits (&hBitStream->hBitBuf) ; const INT freeBits = (CACHE_BITS-1) - BitsInCache ; const INT bitsToRead = (freeBits <= validBits) ? freeBits : validBits ; -- cgit v1.2.3