diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-01-04 10:13:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-04 10:13:15 +0100 |
commit | bdbcf29246bad902e94c3a5fb1fd1abb06aeb2ae (patch) | |
tree | c85c2c9a80d04e338cf39d0fed3fdba2d0291b29 /thirdparty/zstd/common/entropy_common.c | |
parent | b1e3215f3a316cfaf518747f7dafba4cc0d8d291 (diff) | |
parent | e64391f47bf95ab4cdb65683623979ee6790836e (diff) |
Merge pull request #24754 from guilhermefelipecgs/fix_17374
Update zstd to 1.3.8
Diffstat (limited to 'thirdparty/zstd/common/entropy_common.c')
-rw-r--r-- | thirdparty/zstd/common/entropy_common.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/thirdparty/zstd/common/entropy_common.c b/thirdparty/zstd/common/entropy_common.c index b37a082fee..b12944e1de 100644 --- a/thirdparty/zstd/common/entropy_common.c +++ b/thirdparty/zstd/common/entropy_common.c @@ -72,7 +72,21 @@ size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned* t unsigned charnum = 0; int previous0 = 0; - if (hbSize < 4) return ERROR(srcSize_wrong); + if (hbSize < 4) { + /* This function only works when hbSize >= 4 */ + char buffer[4]; + memset(buffer, 0, sizeof(buffer)); + memcpy(buffer, headerBuffer, hbSize); + { size_t const countSize = FSE_readNCount(normalizedCounter, maxSVPtr, tableLogPtr, + buffer, sizeof(buffer)); + if (FSE_isError(countSize)) return countSize; + if (countSize > hbSize) return ERROR(corruption_detected); + return countSize; + } } + assert(hbSize >= 4); + + /* init */ + memset(normalizedCounter, 0, (*maxSVPtr+1) * sizeof(normalizedCounter[0])); /* all symbols not present in NCount have a frequency of 0 */ bitStream = MEM_readLE32(ip); nbBits = (bitStream & 0xF) + FSE_MIN_TABLELOG; /* extract tableLog */ if (nbBits > FSE_TABLELOG_ABSOLUTE_MAX) return ERROR(tableLog_tooLarge); @@ -105,6 +119,7 @@ size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned* t if (n0 > *maxSVPtr) return ERROR(maxSymbolValue_tooSmall); while (charnum < n0) normalizedCounter[charnum++] = 0; if ((ip <= iend-7) || (ip + (bitCount>>3) <= iend-4)) { + assert((bitCount >> 3) <= 3); /* For first condition to work */ ip += bitCount>>3; bitCount &= 7; bitStream = MEM_readLE32(ip) >> bitCount; |