]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libelf: check decompressed ZSTD size
authorAleksei Vetrov <vvvvvv@google.com>
Thu, 23 Nov 2023 15:31:47 +0000 (15:31 +0000)
committerMark Wielaard <mark@klomp.org>
Thu, 23 Nov 2023 23:15:41 +0000 (00:15 +0100)
Decompression functions like __libelf_decompress_zlib check that
decompressed data has the same size as it was declared in the header
(size_out argument). The same check is now added to
__libelf_decompress_zstd to make sure that the whole allocated buffer is
initialized.

    * libelf/elf_compress.c (__libelf_decompress_zstd): Use return value
      of ZSTD_decompress to check that decompressed data size is the
      same as size_out of the buffer that was allocated.

Signed-off-by: Aleksei Vetrov <vvvvvv@google.com>
libelf/elf_compress.c

index c7283c6a606395cd880a9c140bd2daabfdcd417b..0ad6a32a7b2f91d5511f97dcce5f44107339c559 100644 (file)
@@ -422,7 +422,7 @@ __libelf_decompress_zstd (void *buf_in, size_t size_in, size_t size_out)
     }
 
   size_t ret = ZSTD_decompress (buf_out, size_out, buf_in, size_in);
-  if (ZSTD_isError (ret))
+  if (unlikely (ZSTD_isError (ret)) || unlikely (ret != size_out))
     {
       free (buf_out);
       __libelf_seterrno (ELF_E_DECOMPRESS_ERROR);