From 1f338eb41c52e6179c87aa1efbb3babe8a823d59 Mon Sep 17 00:00:00 2001 From: James Bonfield Date: Thu, 23 Jan 2025 16:57:35 +0000 Subject: [PATCH] Remove cram seek ability to do range queries via SEEK_CUR. This was a feature that came all the way from the initial index support added to io_lib, but I think it's a misfeature. The consequence of it is on failing with a SEEK_SET (eg network error, or file corruption) it falls back to doing a read-and-discard loop to simulate the seek via SEEK_CUR. This may perhaps be of use when querying stdin, but it's highly unlikely for us to be doing that while also having an index on disk and it's not something we support with other formats. Fixes #1877 --- cram/cram_index.c | 4 +--- cram/cram_io.c | 19 +------------------ 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/cram/cram_index.c b/cram/cram_index.c index 77c953d6c..b08ca5bfd 100644 --- a/cram/cram_index.c +++ b/cram/cram_index.c @@ -580,9 +580,7 @@ int cram_seek_to_refpos(cram_fd *fd, cram_range *r) { // Ideally use an index, so see if we have one. if ((e = cram_index_query(fd, r->refid, r->start, NULL))) { if (0 != cram_seek(fd, e->offset, SEEK_SET)) { - if (0 != cram_seek(fd, e->offset - fd->first_container, SEEK_CUR)) { - ret = -1; goto err; - } + ret = -1; goto err; } } else { // Absent from index, but this most likely means it simply has no data. diff --git a/cram/cram_io.c b/cram/cram_io.c index 5e5891114..09142c43d 100644 --- a/cram/cram_io.c +++ b/cram/cram_io.c @@ -5440,28 +5440,11 @@ cram_fd *cram_dopen(hFILE *fp, const char *filename, const char *mode) { * -1 on failure */ int cram_seek(cram_fd *fd, off_t offset, int whence) { - char buf[65536]; - fd->ooc = 0; cram_drain_rqueue(fd); - if (hseek(fd->fp, offset, whence) >= 0) { - return 0; - } - - if (!(whence == SEEK_CUR && offset >= 0)) - return -1; - - /* Couldn't fseek, but we're in SEEK_CUR mode so read instead */ - while (offset > 0) { - int len = MIN(65536, offset); - if (len != hread(fd->fp, buf, len)) - return -1; - offset -= len; - } - - return 0; + return hseek(fd->fp, offset, whence) >= 0 ? 0 : -1; } /*