From 4edef6b48be0feb831151d5c662a91deaf0a0d05 Mon Sep 17 00:00:00 2001 From: Martin Storsjo Date: Sat, 1 Sep 2018 00:19:10 +0300 Subject: [PATCH] WIP: Testing: Add aborts on overreads --- libFDK/src/FDK_bitbuffer.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libFDK/src/FDK_bitbuffer.cpp b/libFDK/src/FDK_bitbuffer.cpp index 5a256d5..740763d 100644 --- a/libFDK/src/FDK_bitbuffer.cpp +++ b/libFDK/src/FDK_bitbuffer.cpp @@ -106,6 +106,8 @@ amm-info@iis.fraunhofer.de #include "common_fix.h" #include "fixminmax.h" +#include + const UINT BitMask[32 + 1] = { 0x0, 0x1, 0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f, 0xff, 0x1ff, 0x3ff, 0x7ff, @@ -157,7 +159,11 @@ void FDK_ResetBitBuffer(HANDLE_FDK_BITBUF hBitBuf) { #ifndef FUNCTION_FDK_get INT FDK_get(HANDLE_FDK_BITBUF hBitBuf, const UINT numberOfBits) { - if (numberOfBits == 0 || numberOfBits > hBitBuf->ValidBits) return 0; + if (numberOfBits == 0 || numberOfBits > hBitBuf->ValidBits) { +if (numberOfBits > hBitBuf->ValidBits) +abort(); +return 0; +} UINT byteOffset = hBitBuf->BitNdx >> 3; UINT bitOffset = hBitBuf->BitNdx & 0x07; @@ -181,7 +187,10 @@ INT FDK_get(HANDLE_FDK_BITBUF hBitBuf, const UINT numberOfBits) { #ifndef FUNCTION_FDK_get32 INT FDK_get32(HANDLE_FDK_BITBUF hBitBuf) { - if (hBitBuf->ValidBits < 32) return 0; + if (hBitBuf->ValidBits < 32) { +abort(); +return 0; +} UINT BitNdx = hBitBuf->BitNdx + 32; hBitBuf->BitNdx = BitNdx & (hBitBuf->bufBits - 1);