bugGNU Octave - Bugs: bug #49820, fseek fails for large (>4GByte...

 
 

bug #49820: fseek fails for large (>4GByte files)

Submitter:  None
Submitted:  Sat 10 Dec 2016 01:07:15 PM UTC
   
 
Category:  Libraries Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Works For Me Assigned to:  None
Originator Name:  Pat Gioannini Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 4.2.0
Operating System:  * GNU/Linux Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 26 Dec 2016 04:39:47 PM UTC, comment #2: 

No response, closing report.

Rik <rik5>
Group administrator
Sat 10 Dec 2016 04:10:00 PM UTC, comment #1: 

It works for me:


octave:1> version
ans = 4.2.0
octave:2> fid = fopen ("big-file", "r")
fid =  21
octave:3> pos = 2^33
pos =    8.5899e+09
octave:4> fseek (fid, pos)
ans = 0
octave:5> ftell (fid)
ans =    8.5899e+09
octave:6> format long
octave:7> ftell (fid)
ans =  8589934592
octave:8> pos
pos =  8589934592
octave:9> quit

coredump:2311> ls -l big-file
-rw-r--r-- 1 jwe jwe 15172985856 Dec 10 11:00 big-file


In the DEFUN for fseek, it calls the function octave_stream::seek (const octave_value& const octave_value&), which specifically unpacks the offset as a 64-bit value:

http://hg.savannah.gnu.org/hgweb/octave/file/691d81fc885b/libinterp/corefcn/oct-stream.cc#l6117

How is this failing for you?

John W. Eaton <jwe>
Group administrator
Sat 10 Dec 2016 01:07:15 PM UTC, original submission:  

In file_io.cc the function for fseek contains the code:



DEFUN (fseek, args, ,
       doc: /* -*- texinfo -*-
@deftypefn  {} {} fseek (@var{fid}, @var{offset})
@deftypefnx {} {} fseek (@var{fid}, @var{offset}, @var{origin})
@deftypefnx {} {@var{status} =} fseek (@dots{})
Set the file pointer to the location @var{offset} within the file @var{fid}.

The pointer is positioned @var{offset} characters from the @var{origin},
which may be one of the predefined variables @w{@code{SEEK_CUR}} (current
position), @w{@code{SEEK_SET}} (beginning), or @w{@code{SEEK_END}} (end of
file) or strings @qcode{"cof"}, @qcode{"bof"} or @qcode{"eof"}.  If
@var{origin} is omitted, @w{@code{SEEK_SET}} is assumed.  @var{offset} may
be positive, negative, or zero but not all combinations of @var{origin} and
@var{offset} can be realized.

@code{fseek} returns 0 on success and -1 on error.
@seealso{fskipl, frewind, ftell, fopen}
@end deftypefn */)
{
  int nargin = args.length ();

  if (nargin < 2 || nargin > 3)
    print_usage ();

  octave_stream os = octave_stream_list::lookup (args(0), "fseek");

  octave_value origin_arg = (nargin == 3) ? args(2) : octave_value (-1.0);

  return ovl (os.seek (args(1), origin_arg));
}


The conversion from octave_value in the last line converts args(1) to an int (32bits) rather than an off_t (64 bits).  I changed the last two lines of code to be:


  off_t offset = args(1).int64_value();
  return ovl (os.seek (offset, origin_arg));


I am not familiar enough with octal_value to know if this is really the best solution.  However you must treat the offset parameter as a 64 bit (off_t) rather than 32 bits for fseek to work properly.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-12-26 rik5 Open/ClosedOpen Closed
    2016-12-10 jwe StatusNone Works For Me

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code