public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: Fuzzed files in archives
Date: Thu, 27 Oct 2022 18:06:08 +1030	[thread overview]
Message-ID: <Y1o06O9Pp8ncCsOw@squeak.grove.modra.org> (raw)

Given a fuzzed object file in an archive with section size exceeding
file size, objcopy will report an error like "section size (0xfeffffff
bytes) is larger than file size (0x17a bytes)" but will create a copy
of the object laid out for the large section.  That means a large
temporary file on disk that is read back and written to the output
archive, which can take a while.  The output archive is then deleted
due to the error.  Avoid some of this silliness.

	* objcopy.c (copy_section): If section contents cannot be read
	set output section size to zero.

diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 6ffbdf9c681..d20aaef9f4f 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -4418,6 +4418,7 @@ copy_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
 	  || !bfd_convert_section_contents (ibfd, isection, obfd,
 					    &memhunk, &size))
 	{
+	  bfd_set_section_size (osection, 0);
 	  status = 1;
 	  bfd_nonfatal_message (NULL, ibfd, isection, NULL);
 	  free (memhunk);

-- 
Alan Modra
Australia Development Lab, IBM

             reply	other threads:[~2022-10-27  7:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-27  7:36 Alan Modra [this message]
2022-11-09  7:03 Alan Modra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y1o06O9Pp8ncCsOw@squeak.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).