public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Maria Guseva <m.guseva@samsung.com>
To: binutils@sourceware.org
Cc: 'Yury Gribov' <y.gribov@samsung.com>,
	'Slava Garbuzov' <v.garbuzov@samsung.com>
Subject: [PATCH] Fix failure of 32-bit linker on large files
Date: Thu, 03 Apr 2014 09:21:00 -0000	[thread overview]
Message-ID: <01b401cf4f1e$03c689f0$0b539dd0$%guseva@samsung.com> (raw)

Hi all,

I've found that while linking pretty large files the bfd_seek() function may
be called with incorrect negative value of argument "position". The
"position" value is negative due to overflow in local variable of type long.
That happens in _bfd_elf_set_section_contents():

  bfd_signed_vma pos;
  [...]
  pos = hdr->sh_offset + offset;
  if (bfd_seek (abfd, pos, SEEK_SET) != 0

Both addends are of long long type, the result is used as long long as well.
Using the long type for intermediate result seems to be a bug. That leads
32-bit linker to fail for large (~2Gb) files. The Bugzilla entry for this:
https://sourceware.org/bugzilla/show_bug.cgi?id=16803  
Proposed patch is attached.

Regards,
Maria


	PR ld/16803
	Fixed integer overflow.

	* elf.c (_bfd_elf_set_section_contents): Fixed type of local
variable.

diff --git a/bfd/elf.c b/bfd/elf.c
index 3ded683..2fee9ac 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -7800,7 +7800,7 @@ _bfd_elf_set_section_contents (bfd *abfd,
 			       bfd_size_type count)
 {
   Elf_Internal_Shdr *hdr;
-  bfd_signed_vma pos;
+  file_ptr pos;
 
   if (! abfd->output_has_begun
       && ! _bfd_elf_compute_section_file_positions (abfd, NULL))





                 reply	other threads:[~2014-04-03  9:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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='01b401cf4f1e$03c689f0$0b539dd0$%guseva@samsung.com' \
    --to=m.guseva@samsung.com \
    --cc=binutils@sourceware.org \
    --cc=v.garbuzov@samsung.com \
    --cc=y.gribov@samsung.com \
    /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).