Skip to content

Commit 1a975b3

Browse files
committed
Prevent segfault on invalid DP/AD values
When both DP and AD values are present, VAF is calculated as AD/DP. This could result in VAF values bigger than 1 and access beyond array boundaries. Fixes #2102
1 parent c63329b commit 1a975b3

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

vcfstats.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -938,9 +938,12 @@ static inline void update_dvaf(stats_t *stats, bcf1_t *line, int ial, float vaf)
938938
#define vaf2bin(vaf) ((int)nearbyintf((vaf)/0.05))
939939
static inline void update_vaf(vaf_t *smpl_vaf, bcf1_t *line, int ial, float vaf)
940940
{
941-
int idx = vaf2bin(vaf);
942-
if ( bcf_get_variant_type(line,ial)==VCF_SNP ) smpl_vaf->snv[idx]++;
943-
else smpl_vaf->indel[idx]++;
941+
if ( vaf>=0 && vaf<=1 )
942+
{
943+
int idx = vaf2bin(vaf);
944+
if ( bcf_get_variant_type(line,ial)==VCF_SNP ) smpl_vaf->snv[idx]++;
945+
else smpl_vaf->indel[idx]++;
946+
}
944947
}
945948

946949
static inline int calc_sample_depth(args_t *args, int ismpl, bcf_fmt_t *ad_fmt_ptr, bcf_fmt_t *dp_fmt_ptr)

0 commit comments

Comments
 (0)