• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1From 03c171947cc538b04957ac2222ce86e7c0170bd1 Mon Sep 17 00:00:00 2001
2From: Aleksei Vetrov <vvvvvv@google.com>
3Date: Thu, 23 Nov 2023 15:31:47 +0000
4Subject: [PATCH] libelf: check decompressed ZSTD size
5
6Decompression functions like __libelf_decompress_zlib check that
7decompressed data has the same size as it was declared in the header
8(size_out argument). The same check is now added to
9__libelf_decompress_zstd to make sure that the whole allocated buffer is
10initialized.
11
12    * libelf/elf_compress.c (__libelf_decompress_zstd): Use return value
13      of ZSTD_decompress to check that decompressed data size is the
14      same as size_out of the buffer that was allocated.
15
16Signed-off-by: Aleksei Vetrov <vvvvvv@google.com>
17
18diff --git a/libelf/elf_compress.c b/libelf/elf_compress.c
19index c7283c6a..0ad6a32a 100644
20--- a/libelf/elf_compress.c
21+++ b/libelf/elf_compress.c
22@@ -422,7 +422,7 @@ __libelf_decompress_zstd (void *buf_in, size_t size_in, size_t size_out)
23     }
24
25   size_t ret = ZSTD_decompress (buf_out, size_out, buf_in, size_in);
26-  if (ZSTD_isError (ret))
27+  if (unlikely (ZSTD_isError (ret)) || unlikely (ret != size_out))
28     {
29       free (buf_out);
30       __libelf_seterrno (ELF_E_DECOMPRESS_ERROR);
31--
322.43.0.rc1.413.gea7ed67945-goog
33
34