Skip to content

Fix ColumnConst::getExtremes out-of-bounds access - #98263

Merged
alexey-milovidov merged 3 commits into
masterfrom
fix-column-const-get-extremes
Feb 28, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
fix-column-const-get-extremes

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Feb 27, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

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

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

Fix out-of-bounds access in ColumnConst::getExtremes that could cause a crash when extremes = 1 is enabled.

Summary

  • Fix ColumnConst::getExtremes passing the outer start/end to the inner data column (which only has 1 element), causing a PODArray assertion failure
  • The crash was triggered by the AST fuzzer with extremes = 1 when ExtremesTransform called getExtremes(min, max, 0, size()) on a ColumnConst wrapping a ColumnNullable
  • For a constant column the extremes are trivially the constant value itself

CI report: AST fuzzer (amd_debug)

Closes #98240

🤖 Generated with Claude Code

Version info

  • Merged into: 26.3.1.145
  • Backported to: 26.2.2.5

`ColumnConst::getExtremes` was passing the outer `start` and `end`
to the inner data column which only has 1 element. When
`ExtremesTransform` calls `getExtremes(min, max, 0, size())` on a
`ColumnConst`, `size()` returns the number of repeated rows (e.g. 3),
but the inner column has only 1 element, causing an assertion failure
in `PODArray::operator[]`.

For a constant column the extremes are trivially the constant value.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=4e619266af82b18c09f9a7524383f17868c15a54&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_debug%29

Closes #98240

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Feb 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [48f1cc4]

Summary: ✅

alexey-milovidov and others added 2 commits February 27, 2026 21:46
The test uses `extremes = 1`, so the output includes an extremes
section (min/max rows) after the data rows. The reference file was
missing these lines.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@Algunenano Algunenano self-assigned this Feb 28, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Feb 28, 2026
Merged via the queue into master with commit ededb4c Feb 28, 2026
144 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-column-const-get-extremes branch February 28, 2026 16:15
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Feb 28, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Feb 28, 2026
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Feb 28, 2026
clickhouse-gh Bot added a commit that referenced this pull request Feb 28, 2026
Backport #98263 to 26.2: Fix ColumnConst::getExtremes out-of-bounds access
alexey-milovidov added a commit that referenced this pull request Mar 1, 2026
Fix ColumnConst::getExtremes out-of-bounds access

@Algunenano Algunenano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

groeneai added a commit to groeneai/ClickHouse that referenced this pull request Jul 11, 2026
ColumnArray offsets are cumulative array sizes and must be monotonically
non-decreasing. The constructor only checked offsets.back() == getData().size(),
not monotonicity, so a column whose offsets decrease (offsets[i] < offsets[i-1])
passed construction. offsetAt(i) then exceeds offsets[i], and any consumer that
reads the nested column at [offsetAt(i), offsets[i]) indexes it out of bounds.

For Array(Nullable(...)) this reaches ColumnNullable::isNullAt, which reads the
null map PODArray out of bounds:

  PODArray<char8_t>::operator[]   (out of bounds)
  ColumnNullable::isNullAt
  ColumnNullable::compareAtImpl
  ColumnArray::compareAtImpl
  ColumnArray::getExtremes
  ExtremesTransform::transform

In debug/sanitizer builds this trips the PODArray bounds assertion and aborts;
in release it is an out-of-range read. Seen repeatedly by the BuzzHouse fuzzer
(STID 2508-2658 / 2508-2e5d / 2508-2de4) on SELECT ... FORMAT Null with extremes
over an Array(Nullable) column. It is the Array(Nullable) sibling of the Nullable
family in ClickHouse#98240 (whose ColumnConst variant was fixed in ClickHouse#98263).

Fix the root cause instead of the symptom: enforce the monotonicity invariant at
the single point of trust, ColumnArray construction, via chassert. This makes the
offsets always consistent by construction and aborts a producer that builds an
inconsistent column at its own stack in debug/sanitizer builds, where such bugs
are caught, instead of far away in a consumer. It is O(rows) but chassert-gated,
so release builds keep only the existing O(1) last-offset check and pay nothing.

The exact producer of the inconsistent column is not deterministically
reproducible, so no consumer-side workaround and no hand-built column test are
added.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.2-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assertion `(n >= (static_cast<ssize_t>(pad_left_) ? -1 : 0)) && (n <= static_cast<ssize_t>(this->size()))' failed (STID: 0988-287a)

5 participants