Skip to content

csq: fix segfault when the VCF header has no contig lines - #2590

Merged
pd3 merged 1 commit into
samtools:developfrom
balwierz:fix/csq-segfault-no-contigs
Sep 10, 2026
Merged

csq: fix segfault when the VCF header has no contig lines#2590
pd3 merged 1 commit into
samtools:developfrom
balwierz:fix/csq-segfault-no-contigs

Conversation

@balwierz

Copy link
Copy Markdown
Contributor

bcftools csq segfaults on a VCF whose header has no ##contig lines — in init, before any record is read, so even a header-only VCF crashes it.

printf '##fileformat=VCFv4.2\n#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\n' > empty.vcf
bcftools csq -f ref.fa -g annot.gff3.gz empty.vcf   # Segmentation fault

In init_chr_names(), bcf_hdr_seqnames() returns nseq=0 and a non-NULL calloc(0,…) pointer (glibc), so the !vcf guard misses and vcf[0] / strcmp() read past a zero-length array. Fix also guards nseq==0.

In init_chr_names(), bcf_hdr_seqnames() returns nseq=0 and a non-NULL
calloc(0,...) pointer (glibc) when the header has no contigs, so the !vcf
guard misses and vcf[0]/strcmp() dereference garbage past a zero-length
array. This crashes in init, before any record is read. Also guard nseq==0.

Signed-off-by: Piotr Balwierz <balwierz@gmail.com>
@pd3
pd3 merged commit b6e4d4c into samtools:develop Sep 10, 2026
16 checks passed
@pd3

pd3 commented Sep 10, 2026

Copy link
Copy Markdown
Member

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants