[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug binutils/13534] New: ar mishandles files bigger than 2GB

From: fgouget at codeweavers dot com
Subject: [Bug binutils/13534] New: ar mishandles files bigger than 2GB
Date: Wed, 21 Dec 2011 13:10:28 +0000


             Bug #: 13534
           Summary: ar mishandles files bigger than 2GB
           Product: binutils
           Version: 2.23 (HEAD)
            Status: NEW
          Severity: normal
          Priority: P2
         Component: binutils
        AssignedTo: address@hidden
        ReportedBy: address@hidden
    Classification: Unclassified

Here is how to reproduce the problem:

$ dd if=/dev/zero of=file2G bs=1M count=2049
2049+0 records in
2049+0 records out
2148532224 bytes (2.1 GB) copied, 47.9032 s, 44.9 MB/s
$ ar q ar2G.ar file2G
$ od -a ar2G.ar
0000000   !   <   a   r   c   h   >  nl   f   i   l   e   2   G   /  sp
0000020  sp  sp  sp  sp  sp  sp  sp  sp   1   3   2   4   4   6   6   2
0000040   8   0  sp  sp   1   0   0   0  sp  sp   1   0   0   0  sp  sp
0000060   1   0   0   6   4   4  sp  sp   -   2   1   4   6   4   3   5
0000100   0   7   `  nl nul nul nul nul nul nul nul nul nul nul nul nul

Note that the archive claims that the 'file2G' size is negative: 
-214643507. This results in an invalid archive that cannot be extracted:

$ ar xv ar2G.ar
x - file2G
ar: ar2G.ar is not a valid archive

As a consequence of this it is impossible to generate Debian packages 
bigger than 2GB (for instance for applications that have a large 

Obviously the file size was stored into a signed 32bit variable. Reading 
the source code shows that it was actually a long which means there will 
be further issues if such an archive is moved from a 32bit system to a 
64bit one.

More precisely, the archive file format is a linked list of element 
headers and relies on these having accurate size information to find the 
position of the next element header. Since the archive format allocates 
10 characters for the file size, it should be able to handle files up to 
10GB. However:

 * Files between 2GiB and 4GiB
   The file size is stored as being negative. The archive cannot be 
   extracted by either the 32bit ar or the 64bit one.

 * Files between 4GiB and 10GB
   Only the first 32bits are taken into account so ar will write a size 
   of 0.1GiB for a 4.1GiB file. As a result, during extraction ar will 
   think there is an archive element header in the middle of the file, 
   resulting in an error (if not worse).
   There are also sign issues between 6GiB and 8GiB.

 * Files bigger than 10GB
   ar will silently truncated the file size to its first 10 decimal 
   digits. Decoding will fail for the same reason as above.

Even 64bit systems are not immune to these issues due to the file sizes 
being stored in 'unsigned int' variables in various places.

Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]