From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Alex Shumsky Date: Mon, 27 Nov 2023 18:24:13 +0000 Subject: Fix invalid maxWindowSize in zstd_decompress Signed-off-by: Alex Shumsky --- lib/zstd/zstd.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/zstd/zstd.c b/lib/zstd/zstd.c index bf9cd19cfa..fa40473254 100644 --- a/lib/zstd/zstd.c +++ b/lib/zstd/zstd.c @@ -8,29 +8,34 @@ #include #include #include #include #include +#include "zstd_internal.h" // MAX int zstd_decompress(struct abuf *in, struct abuf *out) { ZSTD_DStream *dstream; ZSTD_inBuffer in_buf; ZSTD_outBuffer out_buf; void *workspace; size_t wsize; int ret; + size_t maxWindowSize; - wsize = ZSTD_DStreamWorkspaceBound(abuf_size(in)); + // compressed data size seems to be totally irrelevant as measure + // of maxWindowSize, but leave it here for safety + maxWindowSize = MAX(abuf_size(in), 128*1024); + wsize = ZSTD_DStreamWorkspaceBound(maxWindowSize); workspace = malloc(wsize); if (!workspace) { debug("%s: cannot allocate workspace of size %zu\n", __func__, wsize); return -ENOMEM; } - dstream = ZSTD_initDStream(abuf_size(in), workspace, wsize); + dstream = ZSTD_initDStream(maxWindowSize, workspace, wsize); if (!dstream) { log_err("%s: ZSTD_initDStream failed\n", __func__); ret = -EPERM; goto do_free; } -- Created with Armbian build tools https://github.com/armbian/build