diff options
Diffstat (limited to 'src/main/extractor_datasource.c')
-rw-r--r-- | src/main/extractor_datasource.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/main/extractor_datasource.c b/src/main/extractor_datasource.c index 0aaafcb..f15321f 100644 --- a/src/main/extractor_datasource.c +++ b/src/main/extractor_datasource.c | |||
@@ -320,15 +320,13 @@ static int64_t | |||
320 | bfds_seek (struct BufferedFileDataSource *bfds, | 320 | bfds_seek (struct BufferedFileDataSource *bfds, |
321 | int64_t pos, int whence) | 321 | int64_t pos, int whence) |
322 | { | 322 | { |
323 | uint64_t npos; | ||
324 | |||
323 | switch (whence) | 325 | switch (whence) |
324 | { | 326 | { |
325 | case SEEK_CUR: | 327 | case SEEK_CUR: |
326 | if (bfds->fpos + bfds->buffer_pos + pos < 0) | 328 | npos = bfds->fpos + bfds->buffer_pos + pos; |
327 | { | 329 | if (npos > bfds->fsize) |
328 | LOG ("Invalid seek operation\n"); | ||
329 | return -1; | ||
330 | } | ||
331 | if (bfds->fpos + bfds->buffer_pos + pos > bfds->fsize) | ||
332 | { | 330 | { |
333 | LOG ("Invalid seek operation to %lld from %llu (max is %llu)\n", | 331 | LOG ("Invalid seek operation to %lld from %llu (max is %llu)\n", |
334 | (long long) pos, | 332 | (long long) pos, |
@@ -341,15 +339,15 @@ bfds_seek (struct BufferedFileDataSource *bfds, | |||
341 | (bfds->buffer_pos + pos >= 0) ) ) | 339 | (bfds->buffer_pos + pos >= 0) ) ) |
342 | { | 340 | { |
343 | bfds->buffer_pos += pos; | 341 | bfds->buffer_pos += pos; |
344 | return bfds->buffer_pos + bfds->fpos; | 342 | return npos; |
345 | } | 343 | } |
346 | if (0 != bfds_pick_next_buffer_at (bfds, | 344 | if (0 != bfds_pick_next_buffer_at (bfds, |
347 | bfds->fpos + bfds->buffer_pos + pos)) | 345 | npos)) |
348 | { | 346 | { |
349 | LOG ("seek operation failed\n"); | 347 | LOG ("seek operation failed\n"); |
350 | return -1; | 348 | return -1; |
351 | } | 349 | } |
352 | return bfds->fpos; | 350 | return npos; |
353 | case SEEK_END: | 351 | case SEEK_END: |
354 | if (pos > 0) | 352 | if (pos > 0) |
355 | { | 353 | { |