]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Fix ZSTD_initCStream_advanced() with no dictionary and static allocation
authorNick Terrell <terrelln@fb.com>
Fri, 14 Aug 2020 19:42:06 +0000 (12:42 -0700)
committerNick Terrell <terrelln@fb.com>
Wed, 9 Sep 2020 21:35:39 +0000 (14:35 -0700)
lib/compress/zstd_compress.c

index 85b04a87837b7c77ebcedfde783e69e2f81811fb..e205ffd0f986c6bfbb6af46f94022f26c6d48948 100644 (file)
@@ -894,8 +894,6 @@ size_t ZSTD_CCtx_loadDictionary_advanced(
 {
     RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong,
                     "Can't load a dictionary when ctx is not in init stage.");
-    RETURN_ERROR_IF(cctx->staticSize, memory_allocation,
-                    "no malloc for static CCtx");
     DEBUGLOG(4, "ZSTD_CCtx_loadDictionary_advanced (size: %u)", (U32)dictSize);
     ZSTD_clearAllDicts(cctx);  /* in case one already exists */
     if (dict == NULL || dictSize == 0)  /* no dictionary mode */
@@ -903,7 +901,10 @@ size_t ZSTD_CCtx_loadDictionary_advanced(
     if (dictLoadMethod == ZSTD_dlm_byRef) {
         cctx->localDict.dict = dict;
     } else {
-        void* dictBuffer = ZSTD_customMalloc(dictSize, cctx->customMem);
+        void* dictBuffer;
+        RETURN_ERROR_IF(cctx->staticSize, memory_allocation,
+                        "no malloc for static CCtx");
+        dictBuffer = ZSTD_customMalloc(dictSize, cctx->customMem);
         RETURN_ERROR_IF(!dictBuffer, memory_allocation, "NULL pointer!");
         ZSTD_memcpy(dictBuffer, dict, dictSize);
         cctx->localDict.dictBuffer = dictBuffer;