read() cant read files larger than 2.1 gig on a 64 bit system

Kees Cook kees at ubuntu.com
Sat Dec 26 09:28:06 GMT 2009


Hi,

On Fri, Dec 25, 2009 at 04:30:46PM -0500, glide creme wrote:
> I can't read files larger than 2 gig on my ubuntu64bit using posix
> 'read()', the problem is not related to the allocation itself, which
> works.

ISTR this being an intentional limitation imposed[1] by the kernel
because there were too many signedness errors being introduced as a
side-effect of attempting to support 64bit reads.  And since short reads
are "valid", it's not really an error, you just have to continue reading.
Using the fopen/fread style calls will let glibc handle the short reads
automatically for you:

 FILE *fd;
 ...
 if ((fd = fopen(infile,"r")) < 0)
   err(EX_NOINPUT, "%s", infile);
 ...
 bytes_read = fread(data, 1, bytes_expected, fd);

-Kees

[1] http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=e28cc715

-- 
Kees Cook
Ubuntu Security Team



More information about the ubuntu-devel mailing list