Skip to content

Commit

Permalink
Prevent negative rlen on erroneous INFO/END when reading BCF
Browse files Browse the repository at this point in the history
This is an extension of ea879e1 which added checks for reading
VCF.

Resolves samtools/bcftools#1154
  • Loading branch information
pd3 committed Feb 12, 2020
1 parent bfc9f0d commit 77fbb03
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion vcf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3895,6 +3895,8 @@ int bcf_get_variant_type(bcf1_t *rec, int ith_allele)

int bcf_update_info(const bcf_hdr_t *hdr, bcf1_t *line, const char *key, const void *values, int n, int type)
{
static int negative_rlen_warned = 0;

// Is the field already present?
int i, inf_id = bcf_hdr_id2int(hdr,BCF_DT_ID,key);
if ( !bcf_hdr_idinfo_exists(hdr,BCF_HL_INFO,inf_id) ) return -1; // No such INFO field in the header
Expand Down Expand Up @@ -3991,7 +3993,16 @@ int bcf_update_info(const bcf_hdr_t *hdr, bcf1_t *line, const char *key, const v
if ( n==1 && !strcmp("END",key) ) {
assert(type == BCF_HT_INT || type == BCF_HT_LONG);
int64_t end = type == BCF_HT_INT ? *(int32_t *) values : *(int64_t *) values;
line->rlen = end - line->pos;
if ( end <= line->pos )
{
if ( !negative_rlen_warned )
{
hts_log_warning("INFO/END=%"PRIhts_pos" is smaller than POS at %s:%"PRIhts_pos,end,bcf_seqname(hdr,line),line->pos+1);
negative_rlen_warned = 1;
}
}
else
line->rlen = end - line->pos;
}
return 0;
}
Expand Down

0 comments on commit 77fbb03

Please sign in to comment.