This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: binutils/14933: ar & ranlib generate truncated files on

32bit filesystem


This patch

doesn't properly check 4Gb indicies in bsd_write_armap.  It has 2 problems:

1. It doesn't work with 32-bit file_ptr.
2. It returns error on indicies from 0x80000000 to 0xffffffff.

However, coff_write_armap change works fine.  This patch applies the
same logic in bsd_write_armap.  I think it is an obvious fix for trunk
and 2.23.


2012-12-09  H.J. Lu  <>

	PR binutils/14933
	* archive.c (bsd_write_armap): Properly check indicies bigger than

diff --git a/bfd/archive.c b/bfd/archive.c
index 8e8fd2d..2fdc8b9 100644
--- a/bfd/archive.c
+++ b/bfd/archive.c
@@ -2424,9 +2424,6 @@ bsd_write_armap (bfd *arch,
   unsigned int count;
   struct ar_hdr hdr;
   long uid, gid;
-  file_ptr max_first_real = 1;
-  max_first_real <<= 31;
   firstreal = mapsize + elength + sizeof (struct ar_hdr) + SARMAG;
@@ -2469,6 +2466,7 @@ bsd_write_armap (bfd *arch,
   for (count = 0; count < orl_count; count++)
+      unsigned int offset;
       bfd_byte buf[BSD_SYMDEF_SIZE];
       if (map[count].u.abfd != last_elt)
@@ -2488,7 +2486,8 @@ bsd_write_armap (bfd *arch,
       /* The archive file format only has 4 bytes to store the offset
 	 of the member.  Check to make sure that firstreal has not grown
 	 too big.  */
-      if (firstreal >= max_first_real)
+      offset = (unsigned int) firstreal;
+      if (firstreal != (file_ptr) offset)
 	  bfd_set_error (bfd_error_file_truncated);
 	  return FALSE;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]