]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fixed round-trip corruption, reported by Oliver Lange
authorYann Collet <yann.collet.73@gmail.com>
Mon, 11 Apr 2016 14:25:56 +0000 (16:25 +0200)
committerYann Collet <yann.collet.73@gmail.com>
Mon, 11 Apr 2016 14:25:56 +0000 (16:25 +0200)
lib/zstd_compress.c
lib/zstd_decompress.c

index 88ef685c9c4c4ff8c4011094bc74b91227adf6fc..48874673c1f94c1767bbcf67d2a5b2940367af54 100644 (file)
@@ -818,7 +818,7 @@ size_t ZSTD_compressSequences(ZSTD_CCtx* zc,
                 FSE_encodeSymbol(&blockStream, &stateMatchLength, mlCode);      /* 24 */  /* 24 */
                 if (MEM_32bits()) BIT_flushBits(&blockStream);                  /* (7)*/
                 FSE_encodeSymbol(&blockStream, &stateLitLength, llCode);        /* 16 */  /* 33 */
-                if (MEM_32bits() || (ofBits+mlBits+llBits > 64-7-(LLFSELog+MLFSELog+OffFSELog)))
+                if (MEM_32bits() || (ofBits+mlBits+llBits >= 64-7-(LLFSELog+MLFSELog+OffFSELog)))
                     BIT_flushBits(&blockStream);                                /* (7)*/
                 BIT_addBits(&blockStream, llTable[n], llBits);
                 if (MEM_32bits() && ((llBits+mlBits)>24)) BIT_flushBits(&blockStream);
@@ -858,7 +858,7 @@ MEM_STATIC void ZSTD_storeSeq(seqStore_t* seqStorePtr, size_t litLength, const B
     static const BYTE* g_start = NULL;
     const U32 pos = (U32)(literals - g_start);
     if (g_start==NULL) g_start = literals;
-    if ((pos > 200000000) && (pos < 200900000))
+    if ((pos > 5810300) && (pos < 5810500))
         printf("Cpos %6u :%5u literals & match %3u bytes at distance %6u \n",
                pos, (U32)litLength, (U32)matchCode+MINMATCH, (U32)offsetCode);
 #endif
index af61ee9d629220eddc4d7b33a57615f2c8026156..5d3f44224dcd629a716e34e05b393e7cd73c9949 100644 (file)
@@ -786,6 +786,16 @@ static size_t ZSTD_decompressSequences(
         for ( ; (BIT_reloadDStream(&(seqState.DStream)) <= BIT_DStream_completed) && nbSeq ; ) {
             nbSeq--;
             ZSTD_decodeSequence(&sequence, &seqState);
+
+#if 0  /* debug */
+            static BYTE* start = NULL;
+            if (start==NULL) start = op;
+            size_t pos = (size_t)(op-start);
+            if ((pos >= 5810037) && (pos < 5810400))
+                printf("Dpos %6u :%5u literals & match %3u bytes at distance %6u \n",
+                       pos, (U32)sequence.litLength, (U32)sequence.matchLength, (U32)sequence.offset);
+#endif
+
             {   size_t const oneSeqSize = ZSTD_execSequence(op, oend, sequence, &litPtr, litLimit_8, base, vBase, dictEnd);
                 if (ZSTD_isError(oneSeqSize)) return oneSeqSize;
                 op += oneSeqSize;