More fixes for buffer overruns instigated by corrupt binaries.
[deliverable/binutils-gdb.git] / bfd / compress.c
index 20eef9528265e905e9b7220e38520625cfb15dea..083a7df1c938492b480e18f712005687c1c23461 100644 (file)
@@ -177,6 +177,13 @@ bfd_get_full_section_contents (bfd *abfd, sec_ptr sec, bfd_byte **ptr)
   switch (sec->compress_status)
     {
     case COMPRESS_SECTION_NONE:
+      /* PR binutils/17512: Avoid malloc or file reading errors due to
+        ridiculous section sizes.  But ignore linker created objects
+        with no contents (yet).  */
+      if (bfd_get_size (abfd) > 0
+         && sz > (bfd_size_type) bfd_get_size (abfd))
+       return FALSE;
+
       if (p == NULL)
        {
          p = (bfd_byte *) bfd_malloc (sz);
This page took 0.026442 seconds and 4 git commands to generate.