]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Fix static analyze error, use proper bounds for dictEnd
authorSen Huang <senhuang96@fb.com>
Thu, 7 Nov 2019 21:24:55 +0000 (16:24 -0500)
committerSen Huang <senhuang96@fb.com>
Fri, 8 Nov 2019 18:57:26 +0000 (13:57 -0500)
lib/compress/zstd_compress.c
lib/dictBuilder/zdict.c

index 247470e5d3f87f775dd621953e6986973cd4c0e5..89c34d5e1c9afcb435459d96589055692821d9e6 100644 (file)
@@ -2772,8 +2772,9 @@ size_t ZSTD_loadCEntropy(ZSTD_compressedBlockState_t* bs, void* workspace,
                          short* offcodeNCount, unsigned* offcodeMaxValue,
                          const void* const dict, size_t dictSize) 
 {
-    const BYTE* dictPtr = (const BYTE*)dict + 8;    /* skip magic num and dict ID */
+    const BYTE* dictPtr = (const BYTE*)dict;    /* skip magic num and dict ID */
     const BYTE* const dictEnd = dictPtr + dictSize;
+    dictPtr += 8;
 
     {   unsigned maxSymbolValue = 255;
         size_t const hufHeaderSize = HUF_readCTable((HUF_CElt*)bs->entropy.huf.CTable, &maxSymbolValue, dictPtr, dictEnd-dictPtr);
index de8576af3f1817f3ab192455699c25dea37ac8c8..9cee71beba3663b6ba2c122322c3b59b5a68312d 100644 (file)
@@ -107,14 +107,15 @@ size_t ZDICT_getDictHeaderSize(const void* dictBuffer, size_t dictSize)
     {   size_t headerSize;
         unsigned offcodeMaxValue = MaxOff;
         ZSTD_compressedBlockState_t* bs = (ZSTD_compressedBlockState_t*)malloc(sizeof(ZSTD_compressedBlockState_t));
+        if (!bs) return ERROR(memory_allocation);
         U32* wksp = (U32*)malloc(HUF_WORKSPACE_SIZE);
+        if (!wksp) return ERROR(memory_allocation);
         short* offcodeNCount = (short*)malloc((MaxOff+1)*sizeof(short));
-        if (!bs || !wksp || !offcodeNCount) {
-            return ERROR(memory_allocation);
-        }
+        if (!offcodeNCount) return ERROR(memory_allocation);
 
         ZSTD_reset_compressedBlockState(bs);
         headerSize = ZSTD_loadCEntropy(bs, wksp, offcodeNCount, &offcodeMaxValue, dictBuffer, dictSize);
+        
         free(bs);
         free(wksp);
         free(offcodeNCount);