Skip to content

Commit

Permalink
Protect against mapped CRAM records at POS 0.
Browse files Browse the repository at this point in the history
We check pos >= ref_len, but didn't check for pos 0 (aka -1 in BAM).

Credit to OSS-Fuzz
Fixes oss-fuzz 70917
  • Loading branch information
jkbonfield authored and whitwham committed Aug 8, 2024
1 parent f1a7ec9 commit 2202fee
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cram/cram_encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -3441,6 +3441,11 @@ static int process_one_read(cram_fd *fd, cram_container *c,
int64_t apos = cr->apos-1, spos = 0;
int64_t MD_last = apos; // last position of edit in MD tag

if (apos < 0) {
hts_log_error("Mapped read with position <= 0 is disallowed");
return -1;
}

cr->cigar = s->ncigar;
cr->ncigar = bam_cigar_len(b);
while (cr->cigar + cr->ncigar >= s->cigar_alloc) {
Expand Down

0 comments on commit 2202fee

Please sign in to comment.