]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Use Working Ctx Logs when not in DMS Mode
authorW. Felix Handte <w@felixhandte.com>
Thu, 13 Sep 2018 18:13:08 +0000 (11:13 -0700)
committerW. Felix Handte <w@felixhandte.com>
Sat, 29 Sep 2018 00:12:54 +0000 (17:12 -0700)
We pre-hash the ptr for the dict match state sometimes. When that actually
happens, a hashlog of 0 can produce undefined behavior (right shift a long
long by 64). Only applies to unoptimized compilations, since when
optimizations are applied, those hash operations are dropped when we're not
actually in dms mode.

lib/compress/zstd_double_fast.c
lib/compress/zstd_fast.c
lib/compress/zstd_opt.c

index 9a2cf89834362f5a9730a0d3d4539fd79e224e0e..7b9e18e7ed9df8b2b2ce62c946c6ead3d79b75f1 100644 (file)
@@ -90,9 +90,9 @@ size_t ZSTD_compressBlock_doubleFast_generic(
                                      prefixLowestIndex - (U32)(dictEnd - dictBase) :
                                      0;
     const U32 dictHBitsL           = dictMode == ZSTD_dictMatchState ?
-                                     dictCParams->hashLog : 0;
+                                     dictCParams->hashLog : hBitsL;
     const U32 dictHBitsS           = dictMode == ZSTD_dictMatchState ?
-                                     dictCParams->chainLog : 0;
+                                     dictCParams->chainLog : hBitsS;
     const U32 dictAndPrefixLength  = (U32)(ip - prefixLowest + dictEnd - dictStart);
 
     assert(dictMode == ZSTD_noDict || dictMode == ZSTD_dictMatchState);
index dfb46abe4cd0db7d479ea25d7dbf2eda14afe230..247746517cd5f10dd45ed6570c90285a74f28fcc 100644 (file)
@@ -82,7 +82,7 @@ size_t ZSTD_compressBlock_fast_generic(
                                      0;
     const U32 dictAndPrefixLength  = (U32)(ip - prefixStart + dictEnd - dictStart);
     const U32 dictHLog             = dictMode == ZSTD_dictMatchState ?
-                                     dictCParams->hashLog : 0;
+                                     dictCParams->hashLog : hlog;
 
     assert(dictMode == ZSTD_noDict || dictMode == ZSTD_dictMatchState);
 
index 170265649bbeef95a4cdf5db5e126c4332805d84..8af69a91d46e2216e72f467fb2ce2ec25f2db2b9 100644 (file)
@@ -533,8 +533,8 @@ U32 ZSTD_insertBtAndGetAllMatches (
     U32         const dmsHighLimit  = dictMode == ZSTD_dictMatchState ? (U32)(dmsEnd - dmsBase) : 0;
     U32         const dmsLowLimit   = dictMode == ZSTD_dictMatchState ? dms->window.lowLimit : 0;
     U32         const dmsIndexDelta = dictMode == ZSTD_dictMatchState ? windowLow - dmsHighLimit : 0;
-    U32         const dmsHashLog    = dictMode == ZSTD_dictMatchState ? dmsCParams->hashLog : 0;
-    U32         const dmsBtLog      = dictMode == ZSTD_dictMatchState ? dmsCParams->chainLog - 1 : 0;
+    U32         const dmsHashLog    = dictMode == ZSTD_dictMatchState ? dmsCParams->hashLog : hashLog;
+    U32         const dmsBtLog      = dictMode == ZSTD_dictMatchState ? dmsCParams->chainLog - 1 : btLog;
     U32         const dmsBtMask     = dictMode == ZSTD_dictMatchState ? (1U << dmsBtLog) - 1 : 0;
     U32         const dmsBtLow      = dictMode == ZSTD_dictMatchState && dmsBtMask < dmsHighLimit - dmsLowLimit ? dmsHighLimit - dmsBtMask : dmsLowLimit;