Skip to content

Commit 1ea5112

Browse files
committed
Fix a segfault on missing tags
If the filtering expression queried keys from a file, for example -i 'INFO/TAG=@strings_expected' the program would segfault if INFO/TAG was not present in the first VCF record. This is now fixed by making sure NULL is not passed to khash_str2int_has_key. Fixes #2111
1 parent ddc1a37 commit 1ea5112

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

filter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* filter.c -- filter expressions.
22
3-
Copyright (C) 2013-2023 Genome Research Ltd.
3+
Copyright (C) 2013-2024 Genome Research Ltd.
44
55
Author: Petr Danecek <[email protected]>
66
@@ -615,7 +615,7 @@ static void filters_cmp_string_hash(token_t *atok, token_t *btok, token_t *rtok,
615615
// there is only one string value, e.g. STR[1][email protected]
616616
if ( btok->idx >= 0 )
617617
{
618-
int ret = khash_str2int_has_key(atok->hash, btok->str_value.s);
618+
int ret = btok->str_value.s ? khash_str2int_has_key(atok->hash, btok->str_value.s) : 0;
619619
if ( rtok->tok_type==TOK_NE ) ret = ret ? 0 : 1;
620620
rtok->pass_site = ret;
621621
return;

test/filter.string.1.1.out

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
##fileformat=VCFv4.2
2+
##FILTER=<ID=PASS,Description="All filters passed">
3+
##INFO=<ID=DP,Number=1,Type=Integer,Description="Approximate read depth (informative and non-informative); some reads may have been filtered based on mapq etc.">
4+
##INFO=<ID=TAG,Number=1,Type=String,Description="This is an example of a string in info.">
5+
##FORMAT=<ID=TAG,Number=1,Type=String,Description="This is an example of a string in format.">
6+
##contig=<ID=chr1,length=248956422>
7+
#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT sample
8+
chr1 11558105 . G C . PASS DP=61;TAG=Example TAG Example

test/filter.string.1.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Example
2+
Something

test/filter.string.1.vcf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
##fileformat=VCFv4.2
2+
##FILTER=<ID=PASS,Description="All filters passed">
3+
##INFO=<ID=DP,Number=1,Type=Integer,Description="Approximate read depth (informative and non-informative); some reads may have been filtered based on mapq etc.">
4+
##INFO=<ID=TAG,Number=1,Type=String,Description="This is an example of a string in info.">
5+
##FORMAT=<ID=TAG,Number=1,Type=String,Description="This is an example of a string in format.">
6+
##contig=<ID=chr1,length=248956422>
7+
#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT sample
8+
chr1 11558102 . G GT . PASS DP=61 . .
9+
chr1 11558105 . G C . PASS DP=61;TAG=Example TAG Example
10+
chr1 11558108 . A T . PASS DP=61;TAG=It TAG It

test/test.pl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@
305305
run_test(\&test_vcf_norm,$opts,in=>'norm.split.merge',out=>'norm.split.merge.4.out',args=>['-m -','-m +any']);
306306
run_test(\&test_vcf_norm,$opts,in=>'norm.merge.4',out=>'norm.merge.4.1.out',args=>'-m +any');
307307
run_test(\&test_vcf_norm,$opts,in=>'norm.merge.4',out=>'norm.merge.4.2.out',args=>'-m +both');
308+
run_test(\&test_vcf_view,$opts,in=>'filter.string.1',out=>'filter.string.1.1.out',args=>q[-i 'INFO/TAG=@{PATH}/filter.string.1.txt']);
309+
run_test(\&test_vcf_view,$opts,in=>'filter.string.1',out=>'filter.string.1.1.out',args=>q[-i 'FMT/TAG=@{PATH}/filter.string.1.txt']);
308310
run_test(\&test_vcf_view,$opts,in=>'merge.gvcf.2.a',out=>'merge.gvcf.2.a.1.out',args=>'-HA');
309311
run_test(\&test_vcf_view,$opts,in=>'merge.gvcf.2.a',out=>'merge.gvcf.2.a.2.out',args=>'-HAA');
310312
run_test(\&test_vcf_view,$opts,in=>'weird-chr-names',out=>'weird-chr-names.1.out',args=>'',reg=>'-r 1');

0 commit comments

Comments
 (0)