#2 Logic bug while trying to seek to last kB

v1.0_(example)
closed
nobody
PDF-parser (6)
5
2014-02-10
2010-07-18
No

The call in the following test:
if(fseek(file, 0L, SEEK_END-1024))
in pdfparser.c will always return -1 with errno == EINVAL, because SEEK_END-1024 isn't a valid value for that parameter.

When looking at the code:
if(fseek(file, 0L, SEEK_END-1024))
e_pos = findTrailer(file, e);
if(e_pos < 0) {
rewind(file);
e_pos = findTrailer(file, e);
}
I assume the logic is to first try to find the trailer in the last kB if there is one, and otherwise search the entire file.
So I think this logic should be rearranged as follows:
if(!fseek(file, -1024, SEEK_END))
e_pos = findTrailer(file, e);
if(e_pos < 0) {
rewind(file);
e_pos = findTrailer(file, e);
}

Discussion

  • Henning Noren

    Henning Noren - 2014-02-10
    • status: open --> closed
    • Group: --> v1.0_(example)
     
  • Henning Noren

    Henning Noren - 2014-02-10

    Thanks, fixed in 0.13

     

Log in to post a comment.