Skip to content

Backport fix for a malformed comparison in a constraint to 26.3 - #123080

Merged
antoniofilipovic merged 2 commits into
26.3from
backport-26.3-comparison-graph-wrong-arity
Oct 1, 2026
Merged

antoniofilipovic merged 2 commits into
26.3from
backport-26.3-comparison-graph-wrong-arity

Conversation

@antoniofilipovic

@antoniofilipovic antoniofilipovic commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

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.

normalizeAtom in src/Interpreters/ComparisonGraph.cpp rewrote less/lessOrEquals into greater/greaterOrEquals by swapping the two arguments without checking how many there were. The constraint AST is not analyzed at that point, so CREATE TABLE ... (CONSTRAINT c CHECK less(a)) or ALTER 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 existing arguments.size() == 2 checks.

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 a CREATE TABLE ... CHECK less(a) reproducer and adds ASSUME less(a) and zero-argument less() cases. The test uses its master name, 04489_constraint_comparison_wrong_arity.

Related: #108768

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed a server crash on CREATE TABLE or ALTER TABLE ... ADD CONSTRAINT when a constraint contains a less or lessOrEquals comparison with the wrong number of arguments, for example CHECK less(a).

🤖 Generated with Claude Code

Version info

  • Merged into: 26.3.38.3

alexey-milovidov and others added 2 commits September 30, 2026 13:56
`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]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [223947e]

Summary: ✅

@clickhouse-gh clickhouse-gh Bot added the comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. label Sep 30, 2026
@antoniofilipovic
antoniofilipovic marked this pull request as ready for review October 1, 2026 07:58
@antoniofilipovic
antoniofilipovic merged commit df02d42 into 26.3 Oct 1, 2026
36 checks passed
@antoniofilipovic
antoniofilipovic deleted the backport-26.3-comparison-graph-wrong-arity branch October 1, 2026 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants