]> git.donarmstrong.com Git - samtools.git/commitdiff
Use bam_validate1() to detect garbage records in the event of a corrupt
authorOn behalf of John Marshall <lh3@sanger.ac.uk>
Fri, 24 Sep 2010 15:08:24 +0000 (15:08 +0000)
committerOn behalf of John Marshall <lh3@sanger.ac.uk>
Fri, 24 Sep 2010 15:08:24 +0000 (15:08 +0000)
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.

bam_index.c

index 263561b0c24f649848d583a6de2e7ff48451f9b2..1ad2e93e5051972b084513d5d7391c45c6cf7bf2 100644 (file)
@@ -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
        }