Bug 14302 - ar mishandles 4GB files
Summary: ar mishandles 4GB files
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.24
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-06-27 09:15 UTC by Francois Gouget
Modified: 2012-06-30 00:54 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
A fix for 'ar tv' and 'ar x' (1.12 KB, patch)
2012-06-27 09:15 UTC, Francois Gouget
Details | Diff
A fix for 'ar tv' and 'ar x' (1.13 KB, patch)
2012-06-27 09:26 UTC, Francois Gouget
Details | Diff
A fix for 'ar tv', 'ar p' and 'ar x' (1.14 KB, patch)
2012-06-27 09:33 UTC, Francois Gouget
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Francois Gouget 2012-06-27 09:15:54 UTC
Created attachment 6488 [details]
A fix for 'ar tv' and 'ar x'

This is similar to bug 13534 but with 4+GB files and only impacts 32bit platforms.

$ dd if=/dev/zero of=file4G bs=1M count=4196
4196+0 records in
4196+0 records out
4399824896 bytes (4.4 GB) copied, 38.398 s, 115 MB/s
$ ~/binutils-cvs/binutils/ar q ar4G.ar file4G
/home/fgouget/binutils-cvs/binutils/ar: creating ar4G.ar
$ od -a ar4G.ar
0000000   !   <   a   r   c   h   >  nl   f   i   l   e   4   G   /  sp
0000020  sp  sp  sp  sp  sp  sp  sp  sp   1   3   4   0   7   8   6   0
0000040   3   0  sp  sp   1   0   0   0  sp  sp   1   0   0   0  sp  sp
0000060   1   0   0   6   4   4  sp  sp   4   3   9   9   8   2   4   8
0000100   9   6   `  nl nul nul nul nul nul nul nul nul nul nul nul nul
0000120 nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul
^C
$ ~/binutils-cvs/binutils/ar tv ar4G.ar
rw-r--r-- 1000/1000 104857600 Jun 27 10:38 2012 file4G
$ ~/binutils-cvs/binutils/ar x ar4G.ar
$ ls -l file4G
-rw-r--r-- 1 fgouget fgouget 104857600 Jun 27 11:11 file41G

The od command shows that the ar archive was created correctly. However 'ar tv' and 'ar x' think it is a 100MB file which is incorrect.

This happens because print_arelt_descr(), print_contents() and extract_file() use 32bit size_t variables instead of bfd_size_type ones.
Comment 1 Francois Gouget 2012-06-27 09:26:26 UTC
Created attachment 6489 [details]
A fix for 'ar tv' and 'ar x'

Updated the commit changelog to reference this bug and be more explicit about the ar commands being fixed.
Comment 2 Francois Gouget 2012-06-27 09:30:08 UTC
Note that 'ar p' is also impacted:

$ ~/binutils-cvs/binutils/ar p ar4G.ar >file4G
$ ls -l file4G
-rw-r--r-- 1 fgouget fgouget 104857600 Jun 27 11:29 file4G
Comment 3 Francois Gouget 2012-06-27 09:33:48 UTC
Created attachment 6490 [details]
A fix for 'ar tv', 'ar p' and 'ar x'
Comment 4 Sourceware Commits 2012-06-29 12:59:54 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	nickc@sourceware.org	2012-06-29 12:59:49

Modified files:
	binutils       : ChangeLog ar.c bucomm.c 

Log message:
	PR binutils/14302
	* bucomm.c (print_arelt_descr): Correctly report the archive size
	field (for 'ar tv').
	* ar.c (print_contents): Use correct types for archive element
	sizes (for 'ar p').
	(extract_file): Likewise (for 'ar x').

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/binutils/ChangeLog.diff?cvsroot=src&r1=1.1918&r2=1.1919
http://sourceware.org/cgi-bin/cvsweb.cgi/src/binutils/ar.c.diff?cvsroot=src&r1=1.84&r2=1.85
http://sourceware.org/cgi-bin/cvsweb.cgi/src/binutils/bucomm.c.diff?cvsroot=src&r1=1.45&r2=1.46
Comment 5 Nick Clifton 2012-06-29 13:02:52 UTC
Hi Francois,

  Thanks for the bug report and patch, and please accept my apologies in getting round to reviewing it.  The patch itself is fine, although there are a couple of places where a comment needs to be updated, and a couple of places where there are now redundant type cases.  I have taken care of both of these things and applied your patch.

Cheers
  Nick
Comment 6 Francois Gouget 2012-06-30 00:54:00 UTC
Thanks for tweaking the patch so it could be committed.