Fix possible array bounds violation in bed_minoff()#1962
Merged
Conversation
Confusion over how to check the number of items in bed_reglist_t::idx could lead to either attempting to read off the end of the array, or returning a value smaller than it should have. The latter was harmless, apart from making lookups slightly slower, but the former could lead to crashes or results not being returned. The correct limit wasn't actually stored directly although it could be calculated from the last range in bed_reglist_t::a. For easier look-ups, it's now stored in bed_reglist_t::max_idx. bed_index_core() is rewritten to store max_idx; add more error and input range checking; and be more efficient. It no longer leaves gaps (filled with -1) in the index it builds, so the code that dealt with them in bed_minoff() can be removed. Some additional changes are made so failures can be passed back and handled appropriately.
Member
Author
|
Added some minor tidying up... |
jkbonfield
added a commit
to jkbonfield/samtools
that referenced
this pull request
Apr 12, 2024
If we run out of memory while calling bed_index then it rightly fails, but in doing so frees ks and str.vs twice. Under normal conditions there were no memory errors. This is a minor error handling glitch that arrived with samtools#1962.
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.
Confusion over how to check the number of items in bed_reglist_t::idx could lead to either attempting to read off the end of the array, or returning a value smaller than it should have. The latter was harmless, apart from making lookups slightly slower, but the former could lead to crashes or results not being returned.
The correct limit wasn't actually stored directly although it could be calculated from the last range in bed_reglist_t::a. For easier look-ups, it's now stored in bed_reglist_t::max_idx.
bed_index_core() is rewritten to store max_idx; add more error and input range checking; and be more efficient. It no longer leaves gaps (filled with -1) in the index it builds, so the code that dealt with them in bed_minoff() can be removed.
Some additional changes are made so failures can be passed back and handled appropriately.
Fixes #1961