Fix crash in getTopKMarks when limit is zero#95072
Merged
alexey-milovidov merged 1 commit intomasterfrom Jan 25, 2026
Merged
Conversation
When `LIMIT -0.` (or any expression that evaluates to 0) is used with `use_skip_indexes_for_top_k = 1`, the `getTopKMarks` functions would call `queue.top()` on an empty priority queue, causing undefined behavior and a segmentation fault. The fix adds an early return when `n == 0` in both `getTopKMarks` overloads, since requesting the top 0 elements should return nothing. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Contributor
|
Workflow [PR], commit [8273bfb] Summary: ❌
|
Member
|
Thanks for the fix! I will adjust my code change for same issue in #93893 |
shankar-iyer
approved these changes
Jan 25, 2026
robot-clickhouse-ci-2
added a commit
that referenced
this pull request
Jan 25, 2026
Cherry pick #95072 to 25.12: Fix crash in `getTopKMarks` when limit is zero
robot-clickhouse
added a commit
that referenced
this pull request
Jan 25, 2026
clickhouse-gh bot
added a commit
that referenced
this pull request
Jan 25, 2026
Backport #95072 to 25.12: Fix crash in `getTopKMarks` when limit is zero
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.
When
LIMIT -0.(or any expression that evaluates to 0) is used withuse_skip_indexes_for_top_k = 1, thegetTopKMarksfunctions would callqueue.top()on an empty priority queue, causing undefined behavior and a segmentation fault.The fix adds an early return when
n == 0in bothgetTopKMarksoverloads, since requesting the top 0 elements should return nothing.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix crash in the top K optimization when
LIMITis zero. Closes #93893.See https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=95065&sha=e047a3f739277d9272ec5108eb879df601c7aaf7&name_0=PR&name_1=AST%20fuzzer%20%28arm_asan%29
Checked manually that the new test reproduces the issue on the debug build.