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 committed Oct 3, 2024
1 parent 2ff207b commit d36f1ae
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 d36f1ae

Please sign in to comment.