Sanity check section size in bfd_init_section_compress_status
authorAlan Modra <amodra@gmail.com>
Wed, 29 Mar 2023 02:15:16 +0000 (12:45 +1030)
committerAlan Modra <amodra@gmail.com>
Wed, 29 Mar 2023 02:26:46 +0000 (12:56 +1030)
This function doesn't just initialise for compression, it actually
compresses.  This patch sanity checks section size before allocating
buffers for the uncompressed contents.

* compress.c (bfd_init_section_compress_status): Sanity check
section size.

bfd/compress.c

index 39f9c50a44575b1119650abb6e08c9051c174f96..844328b27a965f71295adb6d510b402cfdb565fa 100644 (file)
@@ -1065,7 +1065,8 @@ bfd_init_section_compress_status (bfd *abfd, sec_ptr sec)
       || sec->size == 0
       || sec->rawsize != 0
       || sec->contents != NULL
-      || sec->compress_status != COMPRESS_SECTION_NONE)
+      || sec->compress_status != COMPRESS_SECTION_NONE
+      || _bfd_section_size_insane (abfd, sec))
     {
       bfd_set_error (bfd_error_invalid_operation);
       return false;