]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Make ZSTD_compress_usingCDict() respect contentSizeFlag
authorNick Terrell <terrelln@fb.com>
Tue, 4 Apr 2017 04:00:44 +0000 (21:00 -0700)
committerNick Terrell <terrelln@fb.com>
Tue, 4 Apr 2017 04:09:55 +0000 (21:09 -0700)
lib/compress/zstd_compress.c
tests/fuzzer.c

index 03b9758e818d8b2db18f36b60f0c7a1a3ce54326..21f31b756aae346e619fa7d0706bedc1e097e1d8 100644 (file)
@@ -2921,6 +2921,8 @@ size_t ZSTD_compress_usingCDict(ZSTD_CCtx* cctx,
     if (cdict->refContext->params.fParams.contentSizeFlag==1) {
         cctx->params.fParams.contentSizeFlag = 1;
         cctx->frameContentSize = srcSize;
+    } else {
+        cctx->params.fParams.contentSizeFlag = 0;
     }
 
     return ZSTD_compressEnd(cctx, dst, dstCapacity, src, srcSize);
index fed875843489341b9e967976f89d2dc835df2478..342c953e9fe256c4a25181fa9c180f906fb8b0f9 100644 (file)
@@ -404,6 +404,39 @@ static int basicUnitTests(U32 seed, double compressibility)
                   if (r != CNBuffSize) goto _output_error);
         DISPLAYLEVEL(4, "OK \n");
 
+        DISPLAYLEVEL(4, "test%3i : compress with preprocessed dictionary : ", testNb++);
+        {   ZSTD_parameters params = ZSTD_getParams(1, CNBuffSize, dictSize);
+            params.fParams.contentSizeFlag = 0;
+            {   ZSTD_customMem customMem = { NULL, NULL, NULL };
+                ZSTD_CDict* cdict = ZSTD_createCDict_advanced(dictBuffer, dictSize, 1, params, customMem);
+                cSize = ZSTD_compress_usingCDict(cctx, compressedBuffer, ZSTD_compressBound(CNBuffSize),
+                                                 CNBuffer, CNBuffSize, cdict);
+                ZSTD_freeCDict(cdict);
+                if (ZSTD_isError(cSize)) goto _output_error;
+            }
+        }
+        DISPLAYLEVEL(4, "OK (%u bytes : %.2f%%)\n", (U32)cSize, (double)cSize/CNBuffSize*100);
+
+        DISPLAYLEVEL(4, "test%3i : retrieve dictID from frame : ", testNb++);
+        {   U32 const did = ZSTD_getDictID_fromFrame(compressedBuffer, cSize);
+            if (did != dictID) goto _output_error;   /* non-conformant (content-only) dictionary */
+        }
+        DISPLAYLEVEL(4, "OK \n");
+
+        DISPLAYLEVEL(4, "test%3i : frame should not have content size : ", testNb++);
+        {   unsigned long long const contentSize = ZSTD_findDecompressedSize(compressedBuffer, cSize);
+            if (contentSize != ZSTD_CONTENTSIZE_UNKNOWN)  goto _output_error;  /* cdict contentSizeFlag not used */
+        }
+        DISPLAYLEVEL(4, "OK \n");
+
+        DISPLAYLEVEL(4, "test%3i : frame built with dictionary should be decompressible : ", testNb++);
+        CHECKPLUS(r, ZSTD_decompress_usingDict(dctx,
+                                       decodedBuffer, CNBuffSize,
+                                       compressedBuffer, cSize,
+                                       dictBuffer, dictSize),
+                  if (r != CNBuffSize) goto _output_error);
+        DISPLAYLEVEL(4, "OK \n");
+
         DISPLAYLEVEL(4, "test%3i : compress without dictID : ", testNb++);
         {   ZSTD_parameters p = ZSTD_getParams(3, CNBuffSize, dictSize);
             p.fParams.noDictIDFlag = 1;