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"
This commit is contained in:
Olivier Perret 2021-05-12 22:11:15 +02:00 committed by GitHub
parent c730b8c5a3
commit d4548c96cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -951,7 +951,7 @@ static void FIO_adjustParamsForPatchFromMode(FIO_prefs_t* const prefs,
FIO_adjustMemLimitForPatchFromMode(prefs, dictSize, maxSrcFileSize); FIO_adjustMemLimitForPatchFromMode(prefs, dictSize, maxSrcFileSize);
if (fileWindowLog > ZSTD_WINDOWLOG_MAX) if (fileWindowLog > ZSTD_WINDOWLOG_MAX)
DISPLAYLEVEL(1, "Max window log exceeded by file (compression ratio will suffer)\n"); 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 (fileWindowLog > ZSTD_cycleLog(cParams.chainLog, cParams.strategy)) {
if (!prefs->ldmFlag) if (!prefs->ldmFlag)
DISPLAYLEVEL(1, "long mode automatically triggered\n"); DISPLAYLEVEL(1, "long mode automatically triggered\n");