From 43da5bf27e707286ba8679c5f10a109b8a3f1447 Mon Sep 17 00:00:00 2001 From: Bimba Shrestha Date: Thu, 12 Sep 2019 14:43:50 -0700 Subject: [PATCH 1/2] Rearranging assert and allowing 4 extra for FSE_BLOCKBOUND() --- contrib/linux-kernel/lib/zstd/fse.h | 2 +- lib/common/bitstream.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/linux-kernel/lib/zstd/fse.h b/contrib/linux-kernel/lib/zstd/fse.h index 7460ab04..a694199f 100644 --- a/contrib/linux-kernel/lib/zstd/fse.h +++ b/contrib/linux-kernel/lib/zstd/fse.h @@ -232,7 +232,7 @@ If there is an error, the function will return an error code, which can be teste *******************************************/ /* FSE buffer bounds */ #define FSE_NCOUNTBOUND 512 -#define FSE_BLOCKBOUND(size) (size + (size >> 7)) +#define FSE_BLOCKBOUND(size) (size + (size >> 7) + 4 /* constant for initial fse states */ ) #define FSE_COMPRESSBOUND(size) (FSE_NCOUNTBOUND + FSE_BLOCKBOUND(size)) /* Macro version, useful for static allocation */ /* It is possible to statically allocate FSE CTable/DTable as a table of FSE_CTable/FSE_DTable using below macros */ diff --git a/lib/common/bitstream.h b/lib/common/bitstream.h index 7bdb0604..fb10cca3 100644 --- a/lib/common/bitstream.h +++ b/lib/common/bitstream.h @@ -244,9 +244,9 @@ MEM_STATIC void BIT_flushBitsFast(BIT_CStream_t* bitC) { size_t const nbBytes = bitC->bitPos >> 3; assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8); + assert(bitC->ptr <= bitC->endPtr); MEM_writeLEST(bitC->ptr, bitC->bitContainer); bitC->ptr += nbBytes; - assert(bitC->ptr <= bitC->endPtr); bitC->bitPos &= 7; bitC->bitContainer >>= nbBytes*8; } From fe9af338ed9cb1e1b3c2a6a5a219156ad1993e6a Mon Sep 17 00:00:00 2001 From: Bimba Shrestha Date: Thu, 12 Sep 2019 15:35:27 -0700 Subject: [PATCH 2/2] Added assert to BIT_flushBits() --- lib/common/bitstream.h | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/common/bitstream.h b/lib/common/bitstream.h index fb10cca3..306e019c 100644 --- a/lib/common/bitstream.h +++ b/lib/common/bitstream.h @@ -260,6 +260,7 @@ MEM_STATIC void BIT_flushBits(BIT_CStream_t* bitC) { size_t const nbBytes = bitC->bitPos >> 3; assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8); + assert(bitC->ptr <= bitC->endPtr); MEM_writeLEST(bitC->ptr, bitC->bitContainer); bitC->ptr += nbBytes; if (bitC->ptr > bitC->endPtr) bitC->ptr = bitC->endPtr;