From: On behalf of John Marshall Date: Fri, 24 Sep 2010 15:08:24 +0000 (+0000) Subject: Use bam_validate1() to detect garbage records in the event of a corrupt X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=ccd987169ea085165fe156e1727fbb9a33057f7b;p=samtools.git Use bam_validate1() to detect garbage records in the event of a corrupt BAI index file that causes a bam_seek() to an invalid position. At most one record (namely, the bam_iter_read terminator) is tested per bam_fetch() call, so the cost is insignificant in the normal case. --- diff --git a/bam_index.c b/bam_index.c index 263561b..1ad2e93 100644 --- a/bam_index.c +++ b/bam_index.c @@ -676,7 +676,10 @@ int bam_iter_read(bamFile fp, bam_iter_t iter, bam1_t *b) } if ((ret = bam_read1(fp, b)) >= 0) { iter->curr_off = bam_tell(fp); - if (b->core.tid != iter->tid || b->core.pos >= iter->end) { ret = -1; break; } // no need to proceed + if (b->core.tid != iter->tid || b->core.pos >= iter->end) { // no need to proceed + ret = bam_validate1(NULL, b)? -1 : -5; // determine whether end of region or error + break; + } else if (is_overlap(iter->beg, iter->end, b)) return ret; } else break; // end of file or error }