Skip to content

Commit

Permalink
Prevent segfault on empty tbi index
Browse files Browse the repository at this point in the history
When an empty VCF file with a header but no data lines is indexed,
tbx_seqnames() called via bcf_sr_add_reader() returns an empty list.
Consequently, when bcf_sr_regions_next() is called and no in-memory
regions are available, it attempts to read from a file which is
not initialized.

This fixes samtools/bcftools#2286
  • Loading branch information
pd3 authored and daviesrob committed Oct 8, 2024
1 parent 2ff207b commit e0d1956
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion synced_bcf_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,7 @@ int bcf_sr_regions_next(bcf_sr_regions_t *reg)
}

// tabix index absent, reading the whole file
ret = hts_getline(reg->file, KS_SEP_LINE, &reg->line);
ret = reg->file ? hts_getline(reg->file, KS_SEP_LINE, &reg->line) : -1;
if ( ret<0 ) { reg->iseq = -1; return -1; }
}
ret = _regions_parse_line(reg->line.s, ichr,ifrom,ito, &chr,&chr_end,&from,&to);
Expand Down

0 comments on commit e0d1956

Please sign in to comment.