kern/147226: read(fd, buffer, len) returns -1 immediately,
if len >=2147483648
Eugene
eugene.kharitonov at gmail.com
Sun May 30 17:10:06 UTC 2010
>Number: 147226
>Category: kern
>Synopsis: read(fd, buffer, len) returns -1 immediately, if len >=2147483648
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Sun May 30 17:10:06 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator: Eugene
>Release: r200984M
>Organization:
>Environment:
FreeBSD lala.ru 7.2-STABLE FreeBSD 7.2-STABLE #0 r200984M: Fri Apr 23 16:54:24 MSD 2010 root at lala.ru:/place/tmp/mk_pkg.2r1fojOn/obj/place/GIT-repos/FreeBSD-7-r199991/sys/PRODUCTION amd64
>Description:
read(3) returns -1 immediately, if we are trying to read more than 2Gb from file.
>How-To-Repeat:
This code demonstrates the bug:
=====================================
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
int main() {
const size_t bufferSize = 2L * (1 << 30L);
//works
//const size_t toRead = 2L * (1 << 30L) - 1 ;
//do not work
const size_t toRead = 2L * (1 << 30L) ;
fprintf(stderr, "%lu\n", bufferSize);
fprintf(stderr, "%lu\n", sizeof(size_t));
int fd = open("hostlog.dat", O_RDONLY);
char * buffer = (char*) malloc(bufferSize);
if(NULL == buffer) {
fprintf(stderr, "Cannot allocate\n");
abort();
};
ssize_t res = read(fd, buffer, toRead);
fprintf(stderr, "res = %ld\n", res);
free(buffer);
close(fd);
return res;
}
========================================
[kharitonov at lala ~/bugfind]$ gcc44 -m64 -Wall ./do.c
[kharitonov at lala ~/bugfind]$ ./a.out
2147483648
8
res = -1
[kharitonov at lala ~/bugfind]$ ls -l ./hostlog.dat
-rw-rw-r-- 1 kharitonov dev 2346274816 28 May 21:14 ./hostlog.dat
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list