58725c
diff -rup binutils.orig/bfd/elf-attrs.c binutils-2.27/bfd/elf-attrs.c
58725c
--- binutils.orig/bfd/elf-attrs.c	2018-05-30 09:57:23.385080577 +0100
58725c
+++ binutils-2.27/bfd/elf-attrs.c	2018-05-30 10:01:03.528712202 +0100
58725c
@@ -438,6 +438,15 @@ _bfd_elf_parse_attributes (bfd *abfd, El
58725c
   /* PR 17512: file: 2844a11d.  */
58725c
   if (hdr->sh_size == 0)
58725c
     return;
58725c
+  if (hdr->sh_size > bfd_get_size (abfd))
58725c
+    {
58725c
+      /* xgettext:c-format */
58725c
+      _bfd_error_handler (_("%B: error: attribute section '%A' too big: %#llx"),
58725c
+                         abfd, hdr->bfd_section, (long long) hdr->sh_size);
58725c
+      bfd_set_error (bfd_error_invalid_operation);
58725c
+      return;
58725c
+    }
58725c
+
58725c
   contents = (bfd_byte *) bfd_malloc (hdr->sh_size);
58725c
   if (!contents)
58725c
     return;
58725c
diff -rup binutils.orig/bfd/elf.c binutils-2.27/bfd/elf.c
58725c
--- binutils.orig/bfd/elf.c	2018-05-30 09:57:23.382080610 +0100
58725c
+++ binutils-2.27/bfd/elf.c	2018-05-30 10:01:52.766182199 +0100
58725c
@@ -297,6 +297,7 @@ bfd_elf_get_str_section (bfd *abfd, unsi
58725c
       /* Allocate and clear an extra byte at the end, to prevent crashes
58725c
 	 in case the string table is not terminated.  */
58725c
       if (shstrtabsize + 1 <= 1
58725c
+	  || shstrtabsize > bfd_get_size (abfd)
58725c
 	  || bfd_seek (abfd, offset, SEEK_SET) != 0
58725c
 	  || (shstrtab = (bfd_byte *) bfd_alloc (abfd, shstrtabsize + 1)) == NULL)
58725c
 	shstrtab = NULL;