From e0d19561ab1dfc011d9ecb4acf135a7b877f9951 Mon Sep 17 00:00:00 2001 From: Petr Danecek Date: Thu, 3 Oct 2024 13:31:53 +0100 Subject: [PATCH] Prevent segfault on empty tbi index 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 https://github.com/samtools/bcftools/issues/2286 --- synced_bcf_reader.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synced_bcf_reader.c b/synced_bcf_reader.c index 1835ea2d6..ac687ed03 100644 --- a/synced_bcf_reader.c +++ b/synced_bcf_reader.c @@ -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, ®->line); + ret = reg->file ? hts_getline(reg->file, KS_SEP_LINE, ®->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);