Skip to content

Commit

Permalink
lib: decompress_unzstd: Limit output size
Browse files Browse the repository at this point in the history
The zstd decompression code, as it is right now, will most likely fail
on 32-bit systems, as the default output buffer size causes the buffer's
end address to overflow.

Address this issue by setting a sane default to the default output size,
with a value that won't overflow the buffer's end address.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Reviewed-by: Nick Terrell <terrelln@fb.com>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
  • Loading branch information
pcercuei authored and tsbogend committed Sep 3, 2020
1 parent aa9c45d commit 1c4dd33
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/decompress_unzstd.c
Expand Up @@ -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)
/*
Expand Down

0 comments on commit 1c4dd33

Please sign in to comment.