From: Nick Terrell Date: Thu, 18 Jan 2018 21:28:30 +0000 (-0800) Subject: Set repcodes for empty ZSTD_CDict X-Git-Tag: v1.3.4~1^2~73^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d96761520e75d9902bc94cf319e8c18d4ce9e1a;p=thirdparty%2Fzstd.git Set repcodes for empty ZSTD_CDict 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. --- diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index bbe9146bd..9b927367f 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -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(¶ms, 0, sizeof(params));