Skip to content

Commit

Permalink
Fix buffer overrun in bam_plp_insertion_mod.
Browse files Browse the repository at this point in the history
This attempted to grow memory by the maximum amount of space a base
modification would take up, but due to a misunderstanding of kstring
it kept adding this to the original size rather than actually growing
the allocated size.

(Probably) fixes samtools/samtools#1652
  • Loading branch information
jkbonfield committed May 5, 2022
1 parent 3c44c0b commit fae6b3b
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sam.c
Original file line number Diff line number Diff line change
Expand Up @@ -5306,6 +5306,7 @@ int bam_plp_insertion_mod(const bam_pileup1_t *p,
hts_base_mod mod[256];
if (m && (nm = bam_mods_at_qpos(p->b, p->qpos + j - p->is_del,
m, mod, 256)) > 0) {
int o_indel = indel;
if (ks_resize(ins, ins->l + nm*16+3) < 0)
return -1;
ins->s[indel++] = '[';
Expand All @@ -5329,6 +5330,7 @@ int bam_plp_insertion_mod(const bam_pileup1_t *p,
qual);
}
ins->s[indel++] = ']';
ins->l += indel - o_indel; // grow by amount we used
}
}
break;
Expand Down

0 comments on commit fae6b3b

Please sign in to comment.