]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
force contentSizeFlag=0 when using ZSTD_initCStream_usingCDict()
authorYann Collet <cyan@fb.com>
Tue, 11 Apr 2017 18:59:44 +0000 (11:59 -0700)
committerYann Collet <cyan@fb.com>
Tue, 11 Apr 2017 18:59:44 +0000 (11:59 -0700)
because by definition srcSize is not known when using this prototype.
added relevant test

Note : this use was already working, because at a later stage
(both ZSTD_compressBegin_usingCDict() and ZSTD_copyCCtx())
pledgedSrcSize=0 is translated into "unknown", no matter the frame parameter.
This is not correct, but of little importance,
as the medium term plan is to no longer set fParams within CDict

lib/compress/zstd_compress.c
tests/zstreamtest.c

index 62c1c6cdd0a4f73bea0109a6a231554882018250..0ce2054fc628f68f2a879bee741c7789fc407570 100644 (file)
@@ -3077,7 +3077,8 @@ static size_t ZSTD_initCStream_stage2(ZSTD_CStream* zcs,
 size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict)
 {
     if (!cdict) return ERROR(GENERIC);   /* cannot handle NULL cdict (does not know what to do) */
-    {   ZSTD_parameters const params = ZSTD_getParamsFromCDict(cdict);
+    {   ZSTD_parameters params = ZSTD_getParamsFromCDict(cdict);
+        params.fParams.contentSizeFlag = 0;
         zcs->cdict = cdict;
         return ZSTD_initCStream_stage2(zcs, params, 0);
     }
index 6f26ea5555c5004d6ada62571f26da2814ba8b59..ac200a7a698a1ed17ff201be5b84d292588bb7f6 100644 (file)
@@ -448,10 +448,11 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo
       if (!ZSTD_isError(r)) goto _output_error;  /* must fail : frame requires > 100 bytes */
       DISPLAYLEVEL(3, "OK (%s)\n", ZSTD_getErrorName(r)); }
 
-    DISPLAYLEVEL(3, "test%3i : check dictionary used : ", testNb++);
+    DISPLAYLEVEL(3, "test%3i : dictionary compression with masked dictID : ", testNb++);
     {   ZSTD_parameters params = ZSTD_getParams(1, CNBufferSize, dictionary.filled);
         ZSTD_CDict* cdict;
         params.fParams.noDictIDFlag = 1;
+        params.fParams.contentSizeFlag = 1;  /* test contentSize, should be disabled with initCStream_usingCDict */
         cdict = ZSTD_createCDict_advanced(dictionary.start, dictionary.filled, 1, params, customMem);
         { size_t const initError = ZSTD_initCStream_usingCDict(zc, cdict);
           if (ZSTD_isError(initError)) goto _output_error; }
@@ -470,17 +471,20 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo
         cSize = outBuff.pos;
         ZSTD_freeCDict(cdict);
         DISPLAYLEVEL(3, "OK (%u bytes : %.2f%%)\n", (U32)cSize, (double)cSize/CNBufferSize*100);
+    }
 
-        { size_t const r = ZSTD_decompress(decodedBuffer, CNBufferSize, compressedBuffer, cSize);
-          if (!ZSTD_isError(r)) goto _output_error; /* must fail : dictionary not used */
-          DISPLAYLEVEL(3, "OK (%s)\n", ZSTD_getErrorName(r)); }
+    DISPLAYLEVEL(3, "test%3i : decompress without dictionary : ", testNb++);
+    {   size_t const r = ZSTD_decompress(decodedBuffer, CNBufferSize, compressedBuffer, cSize);
+        if (!ZSTD_isError(r)) goto _output_error;  /* must fail : dictionary not used */
+        DISPLAYLEVEL(3, "OK (%s)\n", ZSTD_getErrorName(r));
     }
 
     /* Unknown srcSize */
     DISPLAYLEVEL(3, "test%3i : pledgedSrcSize == 0 behaves properly : ", testNb++);
     {   ZSTD_parameters params = ZSTD_getParams(5, 0, 0);
         params.fParams.contentSizeFlag = 1;
-        ZSTD_initCStream_advanced(zc, NULL, 0, params, 0); } /* cstream advanced should write the 0 size field */
+        ZSTD_initCStream_advanced(zc, NULL, 0, params, 0);
+    } /* cstream advanced shall write content size = 0 */
     inBuff.src = CNBuffer;
     inBuff.size = 0;
     inBuff.pos = 0;