Skip site navigation (1)Skip section navigation (2)
Date:      Mon,  5 Jul 1999 17:02:59 -0700 (PDT)
From:      kientzle@acm.org
To:        freebsd-gnats-submit@freebsd.org
Subject:   misc/12526: fseek(f,o,SEEK_CUR) broken on large files
Message-ID:  <19990706000259.E6B0B15001@hub.freebsd.org>

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

>Number:         12526
>Category:       misc
>Synopsis:       fseek(f,o,SEEK_CUR) broken on large files
>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:   Mon Jul  5 17:10:00 PDT 1999
>Closed-Date:
>Last-Modified:
>Originator:     Tim Kientzle
>Release:        FreeBSD 3.1-RELEASE i386
>Organization:
Independent software consultant
>Environment:
FreeBSD clover.kientzle.com 3.1-RELEASE FreeBSD 3.1-RELEASE #10: Thu Jul  1 13:48:43 PDT 1999     root@clover.kientzle.com:/usr/src/sys/compile/CLOVER  i386
>Description:
fseek() does not properly handle SEEK_CUR if the resulting
file position would exceed 2^31.

(Remember that SEEK_CUR and SEEK_END can both be used to seek
beyond 2^31 even though fseek only accepts a 32-bit signed long offset.)
>How-To-Repeat:
In a 4gig file, perform:

fseek(f,0x7fffffffL, SEEK_SET);
fseek(f,0x7fffffffL, SEEK_CUR); /* This seek silently fails */
>Fix:
fseek() correctly uses 64-bit fpos_t arithmetic to compute the new
file offset when converting SEEK_CUR to SEEK_SET, but then assigns the
64-bit result into the 32-bit 'offset' variable.

This can be fixed by changing the variable 'offset' to a 64-bit fpos_t
type, which in turn requires renaming the actual argument to maintain
the ANSI-dictated interface.  The three lines marked 'TBKK' below are
the necessary changes.
        
/usr/src/lib/libc/stdio/fseek.c:

int
fseek(fp, offset32, whence) /* TBKK: renamed 'offset' to 'offset32' */
        register FILE *fp;
        long offset32; /* TBKK: renamed 'offset' to 'offset32' */
        int whence;
{
        register fpos_t (*seekfn) __P((void *, fpos_t, int));
        fpos_t target, curoff;
        fpos_t offset = offset32; /* TBKK: added 64-bit offset variable */



>Release-Note:
>Audit-Trail:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




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