fix: heap-buffer-overflow in sorted_buffer_gt::insert()#9
Merged
rschu1ze merged 4 commits intoClickHouse/v2.24.0from Apr 3, 2026
Merged
fix: heap-buffer-overflow in sorted_buffer_gt::insert()#9rschu1ze merged 4 commits intoClickHouse/v2.24.0from
rschu1ze merged 4 commits intoClickHouse/v2.24.0from
Conversation
sorted_buffer_gt::insert(element, limit) trusted callers to have reserved at least `limit` elements. When limit > capacity_, the shift-loop (source[1] = source[0]) writes past the heap allocation, triggering ASAN. Root cause: search_to_insert_() and search_to_update_() called top.insert_reserved() and top.insert() without first calling top.reserve(top_limit). Fixes: - reserve(): change < to <= to avoid spurious reallocation when new_capacity == capacity_ - insert_reserved(): guard against zero capacity / full buffer - insert(): clamp limit to capacity to prevent out-of-bounds write - search_to_insert_(): add missing top.reserve() and next.reserve() - search_to_update_(): same missing reserve calls
Remove insert_reserved() zero-capacity guard and insert() limit clamping. These masked bugs rather than surfacing them under ASAN. The real fix is the missing reserve() calls in search_to_insert_() / search_to_update_() and the <= off-by-one in reserve().
alexey-milovidov
approved these changes
Mar 24, 2026
Collaborator
Author
|
@shankar-iyer Thanks for your help with this - could you let me know when / if this is okay to merge? |
Member
|
Port to upstream: unum-cloud#740 |
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.
Summary
Fixes
Tests