Skip to content

Fix possible array bounds violation in bed_minoff()#1962

Merged
whitwham merged 3 commits into
samtools:developfrom
daviesrob:bed_minoff
Jan 17, 2024
Merged

Fix possible array bounds violation in bed_minoff()#1962
whitwham merged 3 commits into
samtools:developfrom
daviesrob:bed_minoff

Conversation

@daviesrob

Copy link
Copy Markdown
Member

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

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.
@daviesrob

Copy link
Copy Markdown
Member Author

Added some minor tidying up...

@whitwham whitwham merged commit 03012f0 into samtools:develop Jan 17, 2024
@daviesrob daviesrob deleted the bed_minoff branch January 18, 2024 09:30
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.
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.

segmentation fault in samtools view 1.19

2 participants