Repository navigation
Backport fix for a malformed comparison in a constraint to 26.3 - #123080
Merged
antoniofilipovic merged 2 commits intoOct 1, 2026
Merged
Conversation
`ComparisonGraph::normalizeAtom` (the AST overload) flips `less`/`lessOrEquals` into `greater`/`greaterOrEquals` by swapping the two arguments, but it accessed `children[0]` and `children[1]` without checking the argument count. The AST reaching `ConstraintsDescription::buildGraph` is not analyzed, so a constraint expression such as `CHECK less(a)` (a unary `less`) caused an out-of-bounds read: `Assertion 'this->m_holder.m_size > n' failed` in debug builds and a segfault in release builds. The query-tree overload is protected by function resolution and its own `chassert(arguments.size() == 2)`; the AST path had no such guard. Only binary comparisons can be normalized, so anything else is left unchanged and ignored later, where `arguments.size() == 2` is already checked. Found by the AST fuzzer on the new `ALTER ... MODIFY CONSTRAINT` test: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108768&sha=686df51dd6d5f41a3043194c6418c5059a53c793&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%29 #108768 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> (cherry picked from commit 01e999e) Co-Authored-By: Claude Opus 5.5 <[email protected]>
The cherry-picked test exercised `ALTER TABLE ... MODIFY CONSTRAINT`, which was introduced together with the fix in #108768 and does not exist on this branch. Replace that case with a `CREATE TABLE` reproducer (`CHECK less(a)`), and cover `ASSUME less(a)` and a zero-argument `less()` as well. Also rename it to `04489_constraint_comparison_wrong_arity`, the name it has on master. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
|
Workflow [BackportPR], commit [223947e] Summary: ✅ |
antoniofilipovic
marked this pull request as ready for review
October 1, 2026 07:58
antonio2368
approved these changes
Oct 1, 2026
antoniofilipovic
deleted the
backport-26.3-comparison-graph-wrong-arity
branch
October 1, 2026 11:52
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.
Manual backport of 01e999e ("Fix out-of-bounds access for a malformed comparison in a constraint"). It reached master inside the feature PR #108768, so it was never picked up by the automatic backports.
normalizeAtominsrc/Interpreters/ComparisonGraph.cpprewroteless/lessOrEqualsintogreater/greaterOrEqualsby swapping the two arguments without checking how many there were. The constraint AST is not analyzed at that point, soCREATE TABLE ... (CONSTRAINT c CHECK less(a))orALTER TABLE ... ADD CONSTRAINT c CHECK less(a)read past the end of the argument vector and crashed the server. The fix only normalizes binary comparisons; anything else is left unchanged and skipped by the existingarguments.size() == 2checks.The first commit is the unchanged cherry-pick. The cherry-picked test used
ALTER TABLE ... MODIFY CONSTRAINT, which does not exist on this branch, so the second commit replaces that case with aCREATE TABLE ... CHECK less(a)reproducer and addsASSUME less(a)and zero-argumentless()cases. The test uses its master name,04489_constraint_comparison_wrong_arity.Related: #108768
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a server crash on
CREATE TABLEorALTER TABLE ... ADD CONSTRAINTwhen a constraint contains alessorlessOrEqualscomparison with the wrong number of arguments, for exampleCHECK less(a).🤖 Generated with Claude Code
Version info
26.3.38.3