Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 30 May 2010 17:06:11 GMT
From:      Eugene <eugene.kharitonov@gmail.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   kern/147226: read(fd, buffer, len) returns -1 immediately, if len >=2147483648
Message-ID:  <201005301706.o4UH6Bdt090307@www.freebsd.org>
Resent-Message-ID: <201005301710.o4UHA6wG072010@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>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@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@lala ~/bugfind]$ gcc44 -m64 -Wall ./do.c
[kharitonov@lala ~/bugfind]$ ./a.out
2147483648
8
res = -1
[kharitonov@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:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201005301706.o4UH6Bdt090307>