diff --git a/lib/common/zbuff_static.h b/lib/common/zbuff_static.h index c50a3e16..44a0321d 100644 --- a/lib/common/zbuff_static.h +++ b/lib/common/zbuff_static.h @@ -32,9 +32,9 @@ #ifndef ZSTD_BUFFERED_STATIC_H #define ZSTD_BUFFERED_STATIC_H -/* The objects defined into this file should be considered experimental. - * They are not labelled stable, as their prototype may change in the future. - * You can use them for tests, provide feedback, or if you can endure risk of future changes. +/* The objects defined into this file must be considered experimental. + * Their prototype may change in future versions. + * Never use them with a dynamic library. */ #if defined (__cplusplus) @@ -54,21 +54,24 @@ extern "C" { * Advanced functions ***************************************/ /*! ZBUFF_createCCtx_advanced() : - * Create a ZBUFF compression context using external alloc and free functions */ + * Create a ZBUFF compression context using external alloc and free functions */ ZSTDLIB_API ZBUFF_CCtx* ZBUFF_createCCtx_advanced(ZSTD_customMem customMem); /*! ZBUFF_createDCtx_advanced() : - * Create a ZBUFF decompression context using external alloc and free functions */ + * Create a ZBUFF decompression context using external alloc and free functions */ ZSTDLIB_API ZBUFF_DCtx* ZBUFF_createDCtx_advanced(ZSTD_customMem customMem); /* ************************************* * Advanced Streaming functions ***************************************/ -ZSTDLIB_API size_t ZBUFF_compressInit_advanced(ZBUFF_CCtx* cctx, +ZSTDLIB_API size_t ZBUFF_compressInit_advanced(ZBUFF_CCtx* zbc, const void* dict, size_t dictSize, ZSTD_parameters params, U64 pledgedSrcSize); + +/* internal util function */ + MEM_STATIC size_t ZBUFF_limitCopy(void* dst, size_t dstCapacity, const void* src, size_t srcSize) { size_t length = ZBUFF_MIN(dstCapacity, srcSize); diff --git a/programs/zbufftest.c b/programs/zbufftest.c index 19a385b4..16692297 100644 --- a/programs/zbufftest.c +++ b/programs/zbufftest.c @@ -212,7 +212,7 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo /* Byte-by-byte decompression test */ DISPLAYLEVEL(4, "test%3i : decompress byte-by-byte : ", testNb++); { size_t r, pIn=0, pOut=0; - do + do { ZBUFF_decompressInitDictionary(zd, CNBuffer, 128 KB); r = 1; while (r) { @@ -346,8 +346,8 @@ static int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compres FUZ_rand(&coreSeed); lseed = coreSeed ^ prime1; - /* state total reset */ - /* some problems only happen when states are re-used in a specific order */ + /* states full reset (unsynchronized) */ + /* some issues only happen when reusing states in a specific sequence of parameters */ if ((FUZ_rand(&lseed) & 0xFF) == 131) { ZBUFF_freeCCtx(zc); zc = ZBUFF_createCCtx(); } if ((FUZ_rand(&lseed) & 0xFF) == 132) { ZBUFF_freeDCtx(zd); zd = ZBUFF_createDCtx(); } @@ -370,15 +370,22 @@ static int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compres { U32 const testLog = FUZ_rand(&lseed) % maxSrcLog; U32 const cLevel = (FUZ_rand(&lseed) % (ZSTD_maxCLevel() - (testLog/3))) + 1; maxTestSize = FUZ_rLogLength(&lseed, testLog); + dictSize = (FUZ_rand(&lseed)==1) ? FUZ_randomLength(&lseed, maxSampleLog) : 0; /* random dictionary selection */ - { size_t dictStart; - dictSize = (FUZ_rand(&lseed)==1) ? FUZ_randomLength(&lseed, maxSampleLog) : 0; - dictStart = FUZ_rand(&lseed) % (srcBufferSize - dictSize); - dict = srcBuffer + dictStart; + { size_t const dictStart = FUZ_rand(&lseed) % (srcBufferSize - dictSize); + dict = srcBuffer + dictStart; } - { size_t const initError = ZBUFF_compressInitDictionary(zc, dict, dictSize, cLevel); - CHECK (ZBUFF_isError(initError),"init error : %s", ZBUFF_getErrorName(initError)); - } } + { ZSTD_compressionParameters cPar = ZSTD_getCParams(cLevel, 0, dictSize); + U32 const checksum = FUZ_rand(&lseed) & 1; + U32 const noDictIDFlag = FUZ_rand(&lseed) & 1; + ZSTD_frameParameters const fPar = { 0, checksum, noDictIDFlag }; + ZSTD_parameters params; + ZSTD_adjustCParams(&cPar, 0, dictSize); + params.cParams = cPar; + params.fParams = fPar; + { size_t const initError = ZBUFF_compressInit_advanced(zc, dict, dictSize, params, 0); + CHECK (ZBUFF_isError(initError),"init error : %s", ZBUFF_getErrorName(initError)); + } } } /* multi-segments compression test */ XXH64_reset(&xxhState, 0);