From d4548c96cb073a575eb616cdff1a95d12f631547 Mon Sep 17 00:00:00 2001 From: Olivier Perret Date: Wed, 12 May 2021 22:11:15 +0200 Subject: [PATCH] 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" --- programs/fileio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/fileio.c b/programs/fileio.c index ec939083..5693ac39 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");