Repository navigation
Fix off-by-one in ToDateMonotonicity boundary check - #98276
Merged
Merged
Conversation
The `toDate` conversion treats values <= `DATE_LUT_MAX_DAY_NUM` (65535) as day numbers and values > 65535 as unix timestamps. This creates a discontinuity at the boundary: `toDate(65535)` = day 65535 but `toDate(65536)` ≈ day 0. The monotonicity check used `left < 0xFFFF` to detect non-monotonic ranges, but this missed the range [65535, 65536] since `65535 < 65535` is false. This caused `MergeTreeSetIndex::checkInRange` to receive an inverted range, triggering LOGICAL_ERROR "Invalid binary search result in MergeTreeSetIndex" in debug builds. Fix the boundary check to use `<= DATE_LUT_MAX_DAY_NUM` and `> DATE_LUT_MAX_DAY_NUM`, matching the actual conversion logic. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=98138&sha=f6eac0762f9799ea48b8e800ef4d22b08c29b699&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%29 Co-Authored-By: Claude Opus 4.6 <[email protected]>
Contributor
| -- Previously caused LOGICAL_ERROR "Invalid binary search result in MergeTreeSetIndex" in debug builds. | ||
| -- https://github.com/ClickHouse/ClickHouse/issues/90461 | ||
|
|
||
| DROP TABLE IF EXISTS t_todate_mono; |
Member
Author
There was a problem hiding this comment.
The test is good.
robot-clickhouse
added a commit
that referenced
this pull request
Mar 1, 2026
This was referenced Mar 1, 2026
robot-clickhouse
added a commit
that referenced
this pull request
Mar 1, 2026
This was referenced Mar 1, 2026
robot-clickhouse
added a commit
that referenced
this pull request
Mar 1, 2026
This was referenced Mar 1, 2026
robot-clickhouse
added a commit
that referenced
this pull request
Mar 1, 2026
This was referenced Mar 1, 2026
robot-clickhouse
added a commit
that referenced
this pull request
Mar 1, 2026
clickhouse-gh Bot
added a commit
that referenced
this pull request
Mar 1, 2026
Backport #98276 to 26.1: Fix off-by-one in ToDateMonotonicity boundary check
clickhouse-gh Bot
added a commit
that referenced
this pull request
Mar 1, 2026
Backport #98276 to 26.2: Fix off-by-one in ToDateMonotonicity boundary check
clickhouse-gh Bot
added a commit
that referenced
this pull request
Mar 1, 2026
Backport #98276 to 25.8: Fix off-by-one in ToDateMonotonicity boundary check
alexey-milovidov
added a commit
that referenced
this pull request
Mar 1, 2026
…ndary Fix off-by-one in ToDateMonotonicity boundary check
alexey-milovidov
added a commit
that referenced
this pull request
Mar 17, 2026
Backport #98276 to 25.3: Fix off-by-one in ToDateMonotonicity boundary check
alexey-milovidov
added a commit
that referenced
this pull request
Mar 17, 2026
Backport #98276 to 25.12: Fix off-by-one in ToDateMonotonicity boundary check
Contributor
|
Hi @alexey-milovidov — while reviewing this PR I found the following:
Happy to discuss — close anything that's wrong or already addressed. |
Contributor
|
Apologies for the duplicate notification — we had a race condition in our notification system where multiple processes posted simultaneously. The duplicate has been removed and we've added a strict 3-layer dedup guard (DB lock + immediate key + GitHub comment check) to ensure this cannot happen again. |
This was referenced Apr 8, 2026
1 task done
1 task
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.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed LOGICAL_ERROR exception "Invalid binary search result in
MergeTreeSetIndex" triggered bytoDateconversion on key columns with data crossing the 65535 boundary.Documentation entry for user-facing changes
No documentation needed — this is a bug fix with no user-facing behavior change.
Fixed off-by-one error in
ToDateMonotonicity::getthat causedLOGICAL_ERROR: Invalid binary search result in MergeTreeSetIndexin debug builds. ThetoDateconversion boundary atDATE_LUT_MAX_DAY_NUM(65535) was checked with< 0xFFFFinstead of<= DATE_LUT_MAX_DAY_NUM, missing the range [65535, 65536] where the function is non-monotonic (jumps from day 65535 to ~day 0). The AST fuzzer found this via a Merge engine table withx Datereading from a MergeTree withx UInt64 ORDER BY x, whereindex_granularity=1creates a mark range [65535, 65536] crossing the boundary.CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=98138&sha=f6eac0762f9799ea48b8e800ef4d22b08c29b699&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%29
#98138
Version info
26.3.1.18226.2.2.7,26.1.4.36,25.12.9.30,25.8.17.37,25.3.15.16