Skip to content

Fix missing header finalization and unchecked faidx return#2536

Closed
sirus20x6 wants to merge 1 commit intosamtools:developfrom
sirus20x6:fix/unchecked-returns-critical
Closed

Fix missing header finalization and unchecked faidx return#2536
sirus20x6 wants to merge 1 commit intosamtools:developfrom
sirus20x6:fix/unchecked-returns-critical

Conversation

@sirus20x6
Copy link
Copy Markdown
Contributor

Summary

  • Add missing bcf_hdr_add_sample(args->header, NULL) in gensample_to_vcf (vcfconvert.c) — header was not finalized after adding samples, matching the pattern in haplegendsample_to_vcf
  • Add NULL check on faidx_fetch_seq return in indel_ctx_type (vcfstats.c) — prevents NULL dereference when chromosome is not in the reference

Test plan

  • Existing test suite passes (1920/1920)
  • Verify bcftools convert --gensample2vcf with sample files
  • Verify bcftools stats --ref-file with mismatched reference

In gensample_to_vcf (vcfconvert.c), add the missing
bcf_hdr_add_sample(header, NULL) finalization call after the sample
addition loop, matching the pattern used in haplegendsample_to_vcf
and other converters.

In indel_ctx_type (vcfstats.c), check faidx_fetch_seq return for NULL
before dereferencing. If the chromosome is absent from the reference,
return the default indel length with nrep=0, nlen=0 instead of
crashing with a NULL pointer dereference.
@sirus20x6 sirus20x6 force-pushed the fix/unchecked-returns-critical branch from f147033 to 119ffec Compare March 26, 2026 00:54
Comment thread vcfconvert.c
*se = 0;
bcf_hdr_add_sample(args->header,samples[i]);
}
bcf_hdr_add_sample(args->header,NULL);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer required, see comments in vcf.c

pd3 added a commit that referenced this pull request Mar 31, 2026
@pd3
Copy link
Copy Markdown
Member

pd3 commented Mar 31, 2026

Resolved via 8cd70c9, the change in vcfconvert.c is not required.

@pd3 pd3 closed this Mar 31, 2026
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