Fix UBSan: negation of signed INT_MIN before cast to unsigned#96979
Merged
alexey-milovidov merged 2 commits intomasterfrom Feb 15, 2026
Merged
Fix UBSan: negation of signed INT_MIN before cast to unsigned#96979alexey-milovidov merged 2 commits intomasterfrom
alexey-milovidov merged 2 commits intomasterfrom
Conversation
…igned The expression `static_cast<UInt64>(-idx)` performs negation in signed domain first, which is undefined behavior when `idx` equals `INT_MIN` (e.g., -2147483648 for Int32). The fix reverses the operations: `-static_cast<UInt64>(idx)` casts to unsigned first, then negates in well-defined unsigned arithmetic. Fixed in `arrayElement.cpp` (the actual UBSan failure from the AST fuzzer) and preventively in `Planner.cpp`, `InterpreterSelectQuery.cpp`, `WindowTransform.cpp`, and `TemporaryDataOnDisk.cpp`. https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=36a049a7f14c6fbc7e0eb33dc32ec94514ceaa7c&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_ubsan%29 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
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
arrayElementwherestatic_cast<UInt64>(-idx)negatesINT_MINin signed domain (UB). Changed to-static_cast<UInt64>(idx)which negates in unsigned domain.Planner,InterpreterSelectQuery,WindowTransform, andTemporaryDataOnDisk.toInt32(-2147483648)array index.AST fuzzer (amd_ubsan) CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=36a049a7f14c6fbc7e0eb33dc32ec94514ceaa7c&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_ubsan%29
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Documentation entry for user-facing changes
🤖 Generated with Claude Code