VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   32 Branches   54 Tags
author: Paul Cercueil <paul@crapouillou.net> 2020-09-01 16:26:50 +0200 committer: Thomas Bogendoerfer <tsbogend@alpha.franken.de> 2020-09-03 10:13:09 +0200 commit: 1c4dd334df3a0627ff57b35612057e2b497e373b parent: aa9c45db018fadd8d15611ba403d4a8e7c6521a9
Commit Summary:
lib: decompress_unzstd: Limit output size
Diffstat:
1 file changed, 6 insertions, 1 deletion
diff --git a/lib/decompress_unzstd.c b/lib/decompress_unzstd.c
index 0ad2c15479ed..790abc472f5b 100644
--- a/lib/decompress_unzstd.c
+++ b/lib/decompress_unzstd.c
@@ -178,8 +178,13 @@ static int INIT __unzstd(unsigned char *in_buf, long in_len,
 	int err;
 	size_t ret;
 
+	/*
+	 * ZSTD decompression code won't be happy if the buffer size is so big
+	 * that its end address overflows. When the size is not provided, make
+	 * it as big as possible without having the end address overflow.
+	 */
 	if (out_len == 0)
-		out_len = LONG_MAX; /* no limit */
+		out_len = UINTPTR_MAX - (uintptr_t)out_buf;
 
 	if (fill == NULL && flush == NULL)
 		/*