]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Set repcodes for empty ZSTD_CDict 997/head
authorNick Terrell <terrelln@fb.com>
Thu, 18 Jan 2018 21:28:30 +0000 (13:28 -0800)
committerNick Terrell <terrelln@fb.com>
Thu, 18 Jan 2018 21:28:30 +0000 (13:28 -0800)
When the dictionary is <= 8 bytes, no data is loaded from the dictionary.
In this case the repcodes weren't set, because they were inserted after the
size check. Fix this problem in general by first setting the cdict state to
a clean state of an empty dictionary, then filling the state from there.

lib/compress/zstd_compress.c

index bbe9146bd2e4ed0322f3fc3e1f43a01a22af360c..9b927367fbe83539a60fef978bb70fc4fd58154f 100644 (file)
@@ -2540,6 +2540,8 @@ static size_t ZSTD_initCDict_internal(
     }
     cdict->dictContentSize = dictSize;
 
+    /* Reset the state to no dictionary */
+    ZSTD_reset_compressedBlockState(&cdict->cBlockState);
     {
         void* const end = ZSTD_reset_matchState(
                 &cdict->matchState,
@@ -2548,6 +2550,9 @@ static size_t ZSTD_initCDict_internal(
         assert(end == (char*)cdict->workspace + cdict->workspaceSize);
         (void)end;
     }
+    /* (Maybe) load the dictionary
+     * Skips loading the dictionary if it is <= 8 bytes.
+     */
     {
         ZSTD_CCtx_params params;
         memset(&params, 0, sizeof(params));