]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fixed asan read error in ZSTD_HcGetAllMatches
authorYann Collet <yann.collet.73@gmail.com>
Thu, 11 Feb 2016 06:14:25 +0000 (07:14 +0100)
committerYann Collet <yann.collet.73@gmail.com>
Thu, 11 Feb 2016 06:14:25 +0000 (07:14 +0100)
lib/zstd_compress.c
lib/zstd_opt.h

index 3ffacc81e2d7571112af3106e3db7e1a7442e10b..39e996c2de09aa6c829ee37910b1b24e473597da 100644 (file)
@@ -1051,7 +1051,7 @@ void ZSTD_compressBlock_fast_generic(ZSTD_CCtx* zc,
 }
 
 
-void ZSTD_compressBlock_fast(ZSTD_CCtx* ctx,
+static void ZSTD_compressBlock_fast(ZSTD_CCtx* ctx,
                        const void* src, size_t srcSize)
 {
     const U32 mls = ctx->params.searchLength;
@@ -1070,8 +1070,7 @@ void ZSTD_compressBlock_fast(ZSTD_CCtx* ctx,
 }
 
 
-//FORCE_INLINE
-void ZSTD_compressBlock_fast_extDict_generic(ZSTD_CCtx* ctx,
+static void ZSTD_compressBlock_fast_extDict_generic(ZSTD_CCtx* ctx,
                                  const void* src, size_t srcSize,
                                  const U32 mls)
 {
@@ -1171,7 +1170,7 @@ void ZSTD_compressBlock_fast_extDict_generic(ZSTD_CCtx* ctx,
 }
 
 
-void ZSTD_compressBlock_fast_extDict(ZSTD_CCtx* ctx,
+static void ZSTD_compressBlock_fast_extDict(ZSTD_CCtx* ctx,
                          const void* src, size_t srcSize)
 {
     const U32 mls = ctx->params.searchLength;
@@ -1288,18 +1287,7 @@ static U32 ZSTD_insertBt1(ZSTD_CCtx* zc, const BYTE* const ip, const U32 mls, co
 }
 
 
-static void ZSTD_updateTree(ZSTD_CCtx* zc, const BYTE* const ip, const BYTE* const iend, const U32 nbCompares, const U32 mls)
-{
-    const BYTE* const base = zc->base;
-    const U32 target = (U32)(ip - base);
-    U32 idx = zc->nextToUpdate;
-
-    for( ; idx < target ; )
-        idx += ZSTD_insertBt1(zc, base+idx, mls, iend, nbCompares, 0);
-}
-
-FORCE_INLINE /* inlining is important to hardwire a hot branch (template emulation) */
-size_t ZSTD_insertBtAndFindBestMatch (
+static size_t ZSTD_insertBtAndFindBestMatch (
                         ZSTD_CCtx* zc,
                         const BYTE* const ip, const BYTE* const iend,
                         size_t* offsetPtr,
@@ -1378,9 +1366,17 @@ size_t ZSTD_insertBtAndFindBestMatch (
 }
 
 
+static void ZSTD_updateTree(ZSTD_CCtx* zc, const BYTE* const ip, const BYTE* const iend, const U32 nbCompares, const U32 mls)
+{
+    const BYTE* const base = zc->base;
+    const U32 target = (U32)(ip - base);
+    U32 idx = zc->nextToUpdate;
+
+    while(idx < target) idx += ZSTD_insertBt1(zc, base+idx, mls, iend, nbCompares, 0);
+}
+
 /** Tree updater, providing best match */
-FORCE_INLINE /* inlining is important to hardwire a hot branch (template emulation) */
-size_t ZSTD_BtFindBestMatch (
+static size_t ZSTD_BtFindBestMatch (
                         ZSTD_CCtx* zc,
                         const BYTE* const ip, const BYTE* const iLimit,
                         size_t* offsetPtr,
@@ -1414,14 +1410,12 @@ static void ZSTD_updateTree_extDict(ZSTD_CCtx* zc, const BYTE* const ip, const B
     const U32 target = (U32)(ip - base);
     U32 idx = zc->nextToUpdate;
 
-    for( ; idx < target ; )
-        idx += ZSTD_insertBt1(zc, base+idx, mls, iend, nbCompares, 1);
+    while (idx < target) idx += ZSTD_insertBt1(zc, base+idx, mls, iend, nbCompares, 1);
 }
 
 
 /** Tree updater, providing best match */
-FORCE_INLINE /* inlining is important to hardwire a hot branch (template emulation) */
-size_t ZSTD_BtFindBestMatch_extDict (
+static size_t ZSTD_BtFindBestMatch_extDict (
                         ZSTD_CCtx* zc,
                         const BYTE* const ip, const BYTE* const iLimit,
                         size_t* offsetPtr,
@@ -1433,7 +1427,7 @@ size_t ZSTD_BtFindBestMatch_extDict (
 }
 
 
-FORCE_INLINE size_t ZSTD_BtFindBestMatch_selectMLS_extDict (
+static size_t ZSTD_BtFindBestMatch_selectMLS_extDict (
                         ZSTD_CCtx* zc,   /* Index table will be updated */
                         const BYTE* ip, const BYTE* const iLimit,
                         size_t* offsetPtr,
index b968bdb0afafc54ce73f95fc334f94a016844f45..1ea88f10327b1b985128fedffe0e79bce5c5a983 100644 (file)
@@ -352,7 +352,7 @@ U32 ZSTD_HcGetAllMatches_generic (
             match = base + matchIndex;
             if (match[minml] == ip[minml]) currentMl = ZSTD_count(ip, match, iHighLimit); if (currentMl>0) {   // faster
             //if (MEM_read32(match) == MEM_read32(ip)) { currentMl = ZSTD_count(ip+MINMATCH, match+MINMATCH, iHighLimit)+MINMATCH;  // stronger
-                while ((match-back > base) && (ip-back > iLowLimit) && (ip[-back-1] == match[-back-1])) back++;
+                while ((match-back > prefixStart) && (ip-back > iLowLimit) && (ip[-back-1] == match[-back-1])) back++;
                 currentMl += back;
             }
         } else {
@@ -448,7 +448,6 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
     ZSTD_resetSeqStore(seqStorePtr);
     if ((ip-base) < REPCODE_STARTVALUE) ip = base + REPCODE_STARTVALUE;
 
-
     /* Match Loop */
     while (ip < ilimit) {
         U32 u;
@@ -480,7 +479,6 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
             } while (mlen >= MINMATCH);
         }
 
-
         best_mlen = (last_pos) ? last_pos : MINMATCH;
 
         if (faster_get_matches && last_pos)
@@ -579,7 +577,6 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
                ZSTD_LOG_PARSER("%d: try REP1 rep=%u mlen=%u\n", (int)(inr-base), (U32)cur_rep, mlen);
            }
 
-
            if (MEM_read32(inr) == MEM_read32(inr - cur_rep)) {  // check rep
                mlen = (U32)ZSTD_count(inr+MINMATCH, inr+MINMATCH - cur_rep, iend) + MINMATCH;
                ZSTD_LOG_PARSER("%d: Found REP mlen=%d off=%d rep=%d opt[%d].off=%d\n", (int)(inr-base), mlen, 0, opt[cur].rep, cur, opt[cur].off);
@@ -594,7 +591,6 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
 
                if (opt[cur].mlen == 1) {
                     litlen = opt[cur].litlen;
-
                     if (cur > litlen) {
                         price = opt[cur - litlen].price + ZSTD_getPrice(seqStorePtr, litlen, inr-litlen, 0, mlen - MINMATCH);
                         ZSTD_LOG_TRY_PRICE("%d: TRY5 opt[%d].price=%d price=%d cur=%d litlen=%d\n", (int)(inr-base), cur - litlen, opt[cur - litlen].price, price, cur, litlen);
@@ -607,9 +603,7 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
                 }
 
                 best_mlen = mlen;
-                if (faster_get_matches)
-                    skip_num = best_mlen;
-
+                if (faster_get_matches) skip_num = best_mlen;
                 ZSTD_LOG_PARSER("%d: Found REP mlen=%d off=%d price=%d litlen=%d price[%d]=%d\n", (int)(inr-base), mlen, 0, price, litlen, cur - litlen, opt[cur - litlen].price);
 
                 do {