]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Put back omission for first rle block and updated comment as suggested
authorBimba Shrestha <bshrestha.msae@gmail.com>
Fri, 6 Sep 2019 20:44:25 +0000 (13:44 -0700)
committerBimba Shrestha <bshrestha.msae@gmail.com>
Fri, 6 Sep 2019 20:44:25 +0000 (13:44 -0700)
lib/compress/zstd_compress.c
lib/compress/zstd_compress_internal.h

index 4ba7798052daeb68522eb162c95e21ad9c804532..f88cc82f0d2dc990c9411fd0c8dfad73b2a9af5b 100644 (file)
@@ -1314,6 +1314,7 @@ static size_t ZSTD_continueCCtx(ZSTD_CCtx* cctx, ZSTD_CCtx_params params, U64 pl
     cctx->blockState.matchState.cParams = params.cParams;
     cctx->pledgedSrcSizePlusOne = pledgedSrcSize+1;
     cctx->consumedSrcSize = 0;
+    cctx->isFirstBlock = 1;
     cctx->producedCSize = 0;
     if (pledgedSrcSize == ZSTD_CONTENTSIZE_UNKNOWN)
         cctx->appliedParams.fParams.contentSizeFlag = 0;
@@ -1416,6 +1417,7 @@ static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx* zc,
                 (U32)pledgedSrcSize, params.cParams.windowLog);
     assert(!ZSTD_isError(ZSTD_checkCParams(params.cParams)));
 
+    zc->isFirstBlock = 1;
     if (crp == ZSTDcrp_continue) {
         if (ZSTD_equivalentParams(zc->appliedParams, params,
                                   zc->inBuffSize,
@@ -2305,6 +2307,11 @@ static size_t ZSTD_compressBlock_internal(ZSTD_CCtx* zc,
             zc->bmi2);
 
     if (frame &&
+        /* We don't want to emit our first block as a RLE even if it qualifies because
+         * doing so will cause the decoder to throw a "should consume all input error."
+         * This is only an issue for zstd <= v1.4.3
+         */
+        !zc->isFirstBlock &&
         cSize < rleMaxLength &&
         ZSTD_isRLE(ip, srcSize))
     {
@@ -2409,6 +2416,7 @@ static size_t ZSTD_compress_frameChunk (ZSTD_CCtx* cctx,
             op += cSize;
             assert(dstCapacity >= cSize);
             dstCapacity -= cSize;
+            cctx->isFirstBlock = 0;
             DEBUGLOG(5, "ZSTD_compress_frameChunk: adding a block of size %u",
                         (unsigned)cSize);
     }   }
index 6d623cc6be8186beab098b430e880a105a6c1b99..3a5c7f2d1b36ae687887e78ef50910277686e01c 100644 (file)
@@ -238,6 +238,7 @@ struct ZSTD_CCtx_s {
     XXH64_state_t xxhState;
     ZSTD_customMem customMem;
     size_t staticSize;
+    int isFirstBlock;
 
     seqStore_t seqStore;      /* sequences storage ptrs */
     ldmState_t ldmState;      /* long distance matching state */