Skip to content

Fix filter engine: OOB write, undefined shift, wrong fallbacks, debug output#2523

Merged
pd3 merged 1 commit intosamtools:developfrom
sirus20x6:fix/filter-engine
Mar 28, 2026
Merged

Fix filter engine: OOB write, undefined shift, wrong fallbacks, debug output#2523
pd3 merged 1 commit intosamtools:developfrom
sirus20x6:fix/filter-engine

Conversation

@sirus20x6
Copy link
Copy Markdown
Contributor

Summary

  • Fix off-by-one in set_genotypes AC bounds check: ial<=line->n_allele to ial<line->n_allele (heap buffer overflow)
  • Fix 1<<allele to 1ULL<<allele in all 4 GT mask sites — allele can be up to 63 but 1<<allele is undefined behavior for signed int when allele >= 31
  • Fix 4 incorrect SMPL_* fallback functions: func_smpl_median fell back to func_avg instead of func_median, and similarly for stddev, sum, and count
  • Remove debug fprintf(stderr,"pass=%d...") left in cmp_vector_strings

Fixes #2491

Test plan

  • Existing test suite passes (1920/1920)
  • Verify SMPL_MEDIAN, SMPL_STDEV, SMPL_SUM, SMPL_COUNT on INFO fields

- vcffilter.c: Fix off-by-one in AC array bounds check (ial<=n_allele
  should be ial<n_allele since tmp_ac has n_allele-1 elements)
- filter.c: Use 1ULL instead of 1 for left shift on allele bitmask to
  avoid undefined behavior when allele >= 32 (mask is uint64_t)
- filter.c: Fix incorrect fallback functions in sample aggregation:
  func_smpl_median -> func_median (was func_avg),
  func_smpl_stddev -> func_stddev (was func_avg),
  func_smpl_sum -> func_sum (was func_avg),
  func_smpl_count -> func_count (was func_max)
- filter.c: Remove debug fprintf left in production code
@pd3 pd3 merged commit bf81630 into samtools:develop Mar 28, 2026
0 of 6 checks passed
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.

bcftools regex filtering expressions produce extra debug output to stderr ("pass="...)

2 participants