X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=bfd%2Fcompress.c;h=ce6bb2beaee689d0eb700f69a08e7eb5fe92ab5c;hb=b899eb3bb807be1094fde9a2f1c8628232bc0743;hp=18a7597f70aaf8f4c24461f29a92aa800e2bdba9;hpb=131a5a648d314cd15811158150573cb40eb3abd0;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/compress.c b/bfd/compress.c index 18a7597f70..ce6bb2beae 100644 --- a/bfd/compress.c +++ b/bfd/compress.c @@ -1,5 +1,5 @@ /* Compressed section support (intended for debug sections). - Copyright (C) 2008-2018 Free Software Foundation, Inc. + Copyright (C) 2008-2020 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -155,8 +155,7 @@ bfd_compress_section_contents (bfd *abfd, sec_ptr sec, return 0; } free (uncompressed_buffer); - bfd_set_section_alignment (abfd, sec, - orig_uncompressed_alignment_pow); + bfd_set_section_alignment (sec, orig_uncompressed_alignment_pow); sec->contents = buffer; sec->compress_status = COMPRESS_SECTION_DONE; @@ -250,6 +249,26 @@ bfd_get_full_section_contents (bfd *abfd, sec_ptr sec, bfd_byte **ptr) case COMPRESS_SECTION_NONE: if (p == NULL) { + ufile_ptr filesize = bfd_get_file_size (abfd); + if (filesize > 0 + && filesize < sz + /* PR 24753: Linker created sections can be larger than + the file size, eg if they are being used to hold stubs. */ + && (bfd_section_flags (sec) & SEC_LINKER_CREATED) == 0 + /* The MMO file format supports its own special compression + technique, but it uses COMPRESS_SECTION_NONE when loading + a section's contents. */ + && bfd_get_flavour (abfd) != bfd_target_mmo_flavour) + { + /* PR 24708: Avoid attempts to allocate a ridiculous amount + of memory. */ + bfd_set_error (bfd_error_no_memory); + _bfd_error_handler + /* xgettext:c-format */ + (_("error: %pB(%pA) section size (%#" PRIx64 " bytes) is larger than file size (%#" PRIx64 " bytes)"), + abfd, sec, (uint64_t) sz, (uint64_t) filesize); + return FALSE; + } p = (bfd_byte *) bfd_malloc (sz); if (p == NULL) { @@ -532,7 +551,7 @@ bfd_init_section_decompress_status (bfd *abfd, sec_ptr sec) sec->compressed_size = sec->size; sec->size = uncompressed_size; - bfd_set_section_alignment (abfd, sec, uncompressed_alignment_power); + bfd_set_section_alignment (sec, uncompressed_alignment_power); sec->compress_status = DECOMPRESS_SECTION_SIZED; return TRUE;