rockchip64: fix uboot zstd decompression

This commit is contained in:
Alex Shumsky 2023-11-27 23:51:49 +03:00 committed by Igor
parent bbdec2dd6e
commit e504369708
1 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,54 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Alex Shumsky <alexthreed@gmail.com>
Date: Mon, 27 Nov 2023 18:24:13 +0000
Subject: Fix invalid maxWindowSize in zstd_decompress
Signed-off-by: Alex Shumsky <alexthreed@gmail.com>
---
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 <common.h>
#include <abuf.h>
#include <log.h>
#include <malloc.h>
#include <linux/zstd.h>
+#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