From: Olivier Perret Date: Wed, 12 May 2021 20:11:15 +0000 (+0200) Subject: fileio: clamp value of windowLog in patch-mode (#2637) X-Git-Tag: v1.5.0^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d4548c96cb073a575eb616cdff1a95d12f631547;p=thirdparty%2Fzstd.git fileio: clamp value of windowLog in patch-mode (#2637) With small enough input files, the inferred value of fileWindowLog could be smaller than ZSTD_WINDOWLOG_MIN. This can be reproduced like so: $ echo abc > small $ echo abcdef > small2 $ zstd --patch-from small small2 -o patch previously, this would fail with the error "zstd: error 11 : Parameter is out of bound" --- diff --git a/programs/fileio.c b/programs/fileio.c index ec9390839..5693ac399 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -951,7 +951,7 @@ static void FIO_adjustParamsForPatchFromMode(FIO_prefs_t* const prefs, FIO_adjustMemLimitForPatchFromMode(prefs, dictSize, maxSrcFileSize); if (fileWindowLog > ZSTD_WINDOWLOG_MAX) DISPLAYLEVEL(1, "Max window log exceeded by file (compression ratio will suffer)\n"); - comprParams->windowLog = MIN(ZSTD_WINDOWLOG_MAX, fileWindowLog); + comprParams->windowLog = MAX(ZSTD_WINDOWLOG_MIN, MIN(ZSTD_WINDOWLOG_MAX, fileWindowLog)); if (fileWindowLog > ZSTD_cycleLog(cParams.chainLog, cParams.strategy)) { if (!prefs->ldmFlag) DISPLAYLEVEL(1, "long mode automatically triggered\n");