From ea2ecdc315fac1017e4a01c1527555377bb08606 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Thu, 14 Jul 2016 22:43:12 +0200 Subject: [PATCH] fixed issue with small dictionary --- .coverity.yml | 5 +++++ NEWS | 3 +++ lib/compress/zstd_compress.c | 9 +++++---- 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 .coverity.yml diff --git a/.coverity.yml b/.coverity.yml new file mode 100644 index 00000000..907f0960 --- /dev/null +++ b/.coverity.yml @@ -0,0 +1,5 @@ +configurationVersion: 1 + +filters: + # third-party embedded + - filePath: lib/dictBuilder/divsufsort.c diff --git a/NEWS b/NEWS index c34f3175..cecc8f49 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,9 @@ v0.7.4 +Added : new examples +Fixed : segfault when using small dictionaries Modified : default compression level for CLI is 3 + v0.7.3 New : compression format specification New : `--` separator, stating that all following arguments are file names. Suggested by Chip Turner. diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index e5838334..ae182a97 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -273,9 +273,10 @@ size_t ZSTD_estimateCCtxSize(ZSTD_compressionParameters cParams) /*! ZSTD_resetCCtx_advanced() : note : 'params' is expected to be validated */ static size_t ZSTD_resetCCtx_advanced (ZSTD_CCtx* zc, - ZSTD_parameters params, U64 frameContentSize, U32 reset) + ZSTD_parameters params, U64 frameContentSize, + U32 reset, U32 fullBlockSize) { /* note : params considered validated here */ - const size_t blockSize = MIN(ZSTD_BLOCKSIZE_MAX, (size_t)1 << params.cParams.windowLog); + const size_t blockSize = fullBlockSize ? ZSTD_BLOCKSIZE_MAX : MIN(ZSTD_BLOCKSIZE_MAX, (size_t)1 << params.cParams.windowLog); const U32 divider = (params.cParams.searchLength==3) ? 3 : 4; const size_t maxNbSeq = blockSize / divider; const size_t tokenSpace = blockSize + 11*maxNbSeq; @@ -357,7 +358,7 @@ size_t ZSTD_copyCCtx(ZSTD_CCtx* dstCCtx, const ZSTD_CCtx* srcCCtx) if (srcCCtx->stage!=1) return ERROR(stage_wrong); memcpy(&dstCCtx->customMem, &srcCCtx->customMem, sizeof(ZSTD_customMem)); - ZSTD_resetCCtx_advanced(dstCCtx, srcCCtx->params, srcCCtx->frameContentSize, 0); + ZSTD_resetCCtx_advanced(dstCCtx, srcCCtx->params, srcCCtx->frameContentSize, 0, 1); dstCCtx->params.fParams.contentSizeFlag = 0; /* content size different from the one set during srcCCtx init */ /* copy tables */ @@ -2694,7 +2695,7 @@ static size_t ZSTD_compressBegin_internal(ZSTD_CCtx* zc, const void* dict, size_t dictSize, ZSTD_parameters params, U64 pledgedSrcSize) { - size_t const resetError = ZSTD_resetCCtx_advanced(zc, params, pledgedSrcSize, 1); + size_t const resetError = ZSTD_resetCCtx_advanced(zc, params, pledgedSrcSize, 1, 0); if (ZSTD_isError(resetError)) return resetError; return ZSTD_compress_insertDictionary(zc, dict, dictSize);