Repository navigation
Conversation
bcf_hdr_t.id[type][i].val points into the vdict hash tables. When bcf_hdr_add_hrec() puts a new key into a dictionary that has reached its upper bound, khash rehashes it and moves every entry, leaving the id pointers dangling until the next bcf_hdr_sync(). Callers commonly add header lines, e.g. with bcf_hdr_printf(), and then carry on using the header without syncing it. `bcftools norm --old-rec-tag` does this, then reads INFO fields through the stale pointers. Since 1.19 bcf_hdr_init() pre-sizes the dictionaries to 16384 buckets, which hides the problem until a header has about 12,600 tags or contigs, but smaller dictionaries expose it in bcftools' own tests under AddressSanitizer. Re-point the affected dictionary's id entries whenever adding a header line rehashes it. Rehashes are rare (the table doubles each time), so this adds O(1) amortised work per line. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Tim Fennell <tfenne@tfenne.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
bcf_hdr_t.id[type][i].val points into the vdict hash tables. When bcf_hdr_add_hrec() puts a new key into a dictionary that has reached its upper bound, khash rehashes it and moves every entry, leaving the id pointers dangling until the next bcf_hdr_sync().
Callers commonly add header lines, e.g. with bcf_hdr_printf(), and then carry on using the header without syncing it.
bcftools norm --old-rec-tagdoes this, then reads INFO fields through the stale pointers. Since 1.19 bcf_hdr_init() pre-sizes the dictionaries to 16384 buckets, which hides the problem until a header has about 12,600 tags or contigs, but smaller dictionaries expose it in bcftools' own tests under AddressSanitizer.Re-point the affected dictionary's id entries whenever adding a header line rehashes it. Rehashes are rare (the table doubles each time), so this adds O(1) amortised work per line.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Tim Fennell tfenne@tfenne.com