]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
objcopy: Don't extend the output section size
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 20 Jun 2025 22:36:56 +0000 (06:36 +0800)
committerH.J. Lu <hjl.tools@gmail.com>
Mon, 23 Jun 2025 14:30:53 +0000 (22:30 +0800)
Since the output section contents are copied from the input, don't
extend the output section size beyond the input section size.

PR binutils/33049
* objcopy.c (copy_section): Don't extend the output section
size beyond the input section size.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
binutils/objcopy.c

index 366e1079d827e5252ea01df2c432e09eed3e98dc..2e98ba44c019f61f889eb7179116543eb97c6385 100644 (file)
@@ -4650,6 +4650,7 @@ copy_section (bfd *ibfd, sec_ptr isection, bfd *obfd)
          char *to = (char *) memhunk;
          char *end = (char *) memhunk + size;
          int i;
+         bfd_size_type memhunk_size = size;
 
          /* If the section address is not exactly divisible by the interleave,
             then we must bias the from address.  If the copy_byte is less than
@@ -4669,6 +4670,11 @@ copy_section (bfd *ibfd, sec_ptr isection, bfd *obfd)
              }
 
          size = (size + interleave - 1 - copy_byte) / interleave * copy_width;
+
+         /* Don't extend the output section size.  */
+         if (size > memhunk_size)
+           size = memhunk_size;
+
          osection->lma /= interleave;
          if (copy_byte < extra)
            osection->lma++;