Skip to content

Fix vcfannotate type mismatch, null deref, and stale buffer#2524

Open
sirus20x6 wants to merge 1 commit intosamtools:developfrom
sirus20x6:fix/vcfannotate-type-safety
Open

Fix vcfannotate type mismatch, null deref, and stale buffer#2524
sirus20x6 wants to merge 1 commit intosamtools:developfrom
sirus20x6:fix/vcfannotate-type-safety

Conversation

@sirus20x6
Copy link
Copy Markdown
Contributor

Summary

  • Fix bcf_get_info_float to bcf_get_info_int32 in setter_ARinfo_int32 — was reading integer data through the float API, corrupting values
  • Add NULL check for tab in setter_info_int and setter_info_real merge-flush paths — uses line->n_allele/line->d.allele when tab is NULL for Number=A/R tags
  • Fix determine_ploidy in vcf_setter_format_real to use float buffers instead of stale int buffers

Test plan

  • Existing test suite passes (updated annotate8.out and annotate15.out)
  • Verify annotation of Number=A/R integer INFO fields and float FORMAT fields with haploid samples

1. setter_ARinfo_int32 (line 788): Used bcf_get_info_float to read int32
   data into an int32 buffer. Changed to bcf_get_info_int32.

2. setter_info_int and setter_info_real: When flushing merged values for
   Number=A/R tags, `tab` (the annotation line) is NULL, causing a null
   pointer dereference. Fall back to line->n_allele and line->d.allele
   when tab is NULL.

3. vcf_setter_format_real: determine_ploidy was called with args->tmpi
   and args->tmpi2 (int buffers) instead of the float buffers (args->tmpf
   and args->tmpf2) that actually hold the format data. Cast the float
   buffers to int* since htslib sentinel values (missing/vector_end) share
   the same bit patterns between float and int32 representations.
@sirus20x6 sirus20x6 force-pushed the fix/vcfannotate-type-safety branch from 09d7de1 to 42bd119 Compare March 26, 2026 00:54
@pd3
Copy link
Copy Markdown
Member

pd3 commented Mar 30, 2026

This is not a good fix, it introduces a bug, casting forcibly float* to int* when calling determine_ploidy()

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