public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix failure of 32-bit linker on large files
@ 2014-04-03  9:21 Maria Guseva
  0 siblings, 0 replies; only message in thread
From: Maria Guseva @ 2014-04-03  9:21 UTC (permalink / raw)
  To: binutils; +Cc: 'Yury Gribov', 'Slava Garbuzov'

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))





^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-04-03  9:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-03  9:21 [PATCH] Fix failure of 32-bit linker on large files Maria Guseva

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).