]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fileio: clamp value of windowLog in patch-mode (#2637)
authorOlivier Perret <Olivier.Perret@mailbox.org>
Wed, 12 May 2021 20:11:15 +0000 (22:11 +0200)
committerGitHub <noreply@github.com>
Wed, 12 May 2021 20:11:15 +0000 (16:11 -0400)
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

index ec9390839ad841bffe2755e41885cab036df2de0..5693ac39936ba4c3b55f2120310a76f14820a16d 100644 (file)
@@ -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");