Skip to content

Verify array offsets read as absolute values, not only in the Native format - #109212

Merged
alexey-milovidov merged 14 commits into
ClickHouse:masterfrom
groeneai:fix-getextremes-array-nullable-oob
Aug 12, 2026
Merged

alexey-milovidov merged 14 commits into
ClickHouse:masterfrom
groeneai:fix-getextremes-array-nullable-oob

Conversation

@groeneai

@groeneai groeneai commented Jul 2, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Rejects non-monotonic Array offsets on every read path that decodes them as absolute values, instead of only in the Native format. A corrupt set skip index granule previously passed unchecked and was then read out of bounds.

Description

SerializationArray::deserializeOffsetsBinaryBulk already refuses decreasing offsets, but the check was gated on settings.native_format, which only NativeReader and NativeWriter ever assign.

That gate does not match what the check is about. The branch immediately above it reads offsets either as sizes, accumulated with a non-negative step so the result is monotonic by construction, or as absolute values taken straight from the stream, where a decreasing sequence is possible. Only the second encoding needs verifying, and Native is not its only user. Both set skip index granule readers set position_independent_encoding = false, so a granule is decoded as absolute offsets with no check; MergeTreeIndexGranuleSet::deserializeBinary then calls getExtremes on the result, which reads the nested column over [offsetAt(i), offsets[i]) and walks past its end when the offsets decrease.

The check is now keyed on the encoding rather than the format. It costs nothing on MergeTree part reads, which do not set position_independent_encoding and so take the sizes branch. The offsets column is appended to across range reads rather than rebuilt per call, so the scan covers only the values the call appended, starting one element early to compare across the range boundary; Native keeps its current error code and message.

Scope: the constructor check this PR originally proposed is dropped, because the read path builds the column through DataTypeArray::createColumn and fills it in place, so the constructor never sees these offsets. This closes an unchecked ingress; it does not identify the producer behind the reported ExtremesTransform extremes, and is not claimed to fix it.

The granule reader decodes from a compressed stream and functional tests must not fabricate part files, so the coverage is a unit test at the ingestion boundary.

Provenance: a BuzzHouse report (STID 2508-2658, CI report) where getExtremes read out of bounds over non-monotonic offsets. Related: #112504 covers the constructor-side half.

Version info

  • Backported to: 26.7.7.57, 26.6.5.84, 26.3.33.48

@groeneai

groeneai commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes for the crash mechanism: a unit test builds a ColumnArray(Nullable) with non-monotonic offsets ({2,5,4}, back()==4== nested size, equal nested values) and, without the guard, aborts with the exact CI assertion (getExtremes -> compareAtImpl -> isNullAt -> PODArray::operator[] OOB). The full production query is a BuzzHouse-generated SELECT ... FORMAT Null over a Log table and the upstream producer of the inconsistent column is not deterministically reproducible.
b Root cause explained? ColumnArray::getExtremes reads the nested column at [offsetAt(i), offsets[i]) per row. The ColumnArray ctor checks only offsets.back() == nested.size(), not monotonicity; a column with decreasing/overshooting offsets passes construction, then compareAtImpl indexes the nested Nullable null map out of bounds -> isNullAt OOB -> abort in debug/sanitizer.
c Fix matches root cause? Yes. The guard validates the exact invariant that keeps the reads in range (offsetAt(i) <= offsets[i] <= nested.size() for every row) at the consumer that trusts it, converting the OOB into a clean INCORRECT_DATA exception. Same approach as the accepted sibling guards ColumnString::insertRangeFrom (#107196) and ColumnString::filter (#109184).
d Test intent preserved / new tests added? New tests only. NonMonotonicOffsetsThrowInsteadOfOOB (the regression) and WellFormedColumnWorks (guard does not reject valid columns / extremes still correct). No existing test weakened.
e Demonstrated in both directions? Yes. Without the guard the regression test aborts with the CI assertion; with the guard it throws INCORRECT_DATA and passes. Well-formed Array(Nullable) extremes (incl. NULLs, Decimal) verified correct via clickhouse-local and the positive gtest; all 30 existing ColumnArray/ColumnString/Nullable/Extremes gtests pass.
f Fix is general, not a narrow patch? The guard covers any inconsistency shape (decreasing offsets or overshoot) for any nested type, not just the one fuzzed input. The identical read pattern in ColumnArray::compareAtImpl is shared by sorting; this PR guards the evidenced consumer (getExtremes, matching the #109184 precedent of guarding the observed consumer) rather than speculatively instrumenting every consumer. The sibling ColumnString paths already received the same class of guard (#107196, #109184).
g Fix generalizes across inputs / datatypes / wrappers? The check is on the array offsets vs nested size and is independent of the nested element type, so it holds for Array(Nullable(T)) for any T, and for non-nullable nested too. Verified with Int64, Nullable(Int64) with NULLs, and Nullable(Decimal).
h Backward compatible? Yes. Well-formed columns are unaffected (the invariant always holds for them). The only behavior change is that a genuinely corrupt column now raises INCORRECT_DATA (caught normally in release) instead of an out-of-range read / debug abort. No setting, format, or on-disk change.
i Invariants and contracts preserved? Yes. The guard enforces the documented ColumnArray offsets/nested-size invariant that getExtremes already relies on; it adds no new invariant and touches no lock/format/ownership contract. The check runs once over [start, end) before the compare loop; getExtremes is not a hot path.

Session id: cron:clickhouse-worker-slot-6:20260702-175800

@groeneai

groeneai commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

cc @Algunenano @CurtizJ could you review this? It adds an O(rows) offsets-consistency guard to ColumnArray::getExtremes that rejects an Array(Nullable) column whose offsets are non-monotonic / overshoot the nested column with INCORRECT_DATA, instead of letting compareAtImpl -> isNullAt read the nested null map out of bounds (BuzzHouse-found abort, the Array(Nullable) sibling of #98240). Same guard pattern as #107196 / #109184.

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Jul 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f936ecb]

Summary: ✅


AI Review

Summary

This PR moves the array-offset validation to the actual absolute-offset decoding path and adds focused regression coverage for decreasing offsets across incremental reads plus the empty-elements corruption case. I reviewed the current diff, the surrounding deserialization code paths, and the full prior thread history, and I did not find a remaining correctness issue in the current implementation.

Final Verdict

✅ No new findings.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.60% 86.60% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.90% 78.80% -0.10%

Changed lines: Changed C/C++ lines covered: 78/80 (97.50%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 2, 2026
@groeneai

groeneai commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 32695b1

CI is complete on this head. No failed tests; all aggregators green (Finish Workflow, Mergeable Check, CH Inc sync all pass).

Check / test Reason Owner / fixing PR
(no failed tests) - -
CH Inc sync - pass

This PR guards ColumnArray::getExtremes against offsets inconsistent with the nested column (the Array(Nullable) sibling of the STID 2508 getExtremes assertion family). Clean run; the added gtest passes and no existing test regressed.

Session id: cron:our-pr-ci-monitor:20260703-000000

@alexey-milovidov

Copy link
Copy Markdown
Member

@groeneai, this is incorrect. The fix should be in the root cause - to make offsets always consistent.
Otherwise this fix gives nothing, and the artificial test is pointless.

@alexey-milovidov
alexey-milovidov marked this pull request as draft July 10, 2026 22:57
@alexey-milovidov alexey-milovidov self-assigned this Jul 10, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

@alexey-milovidov agreed, the guard is a band-aid and the hand-built test proves nothing. I traced the mechanism: the OOB only happens when a ColumnArray reaches getExtremes with non-monotonic offsets (some offsetAt(n)+i exceeds offsets.back(), which for Array(Nullable) equals the nested null map size). The constructor only checks offsets.back() == getData().size(), never monotonicity, so a malformed column passes construction and OOBs later. I will drop this PR's consumer guard + test and hunt the producer that emits the inconsistent offsets, then fix it there. If I cannot reproduce the producer, the honest "always consistent" fix is to enforce the offset invariant at ColumnArray construction rather than at the read site; I will report back with whichever I land.

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]>
@groeneai
groeneai force-pushed the fix-getextremes-array-nullable-oob branch from 32695b1 to e69b71c Compare July 11, 2026 00:35
@groeneai groeneai changed the title Guard ColumnArray::getExtremes against offsets inconsistent with nested column Enforce monotonic offsets invariant in ColumnArray construction Jul 11, 2026
@clickhouse-gh clickhouse-gh Bot added pr-ci and removed pr-bugfix Pull request with bugfix, not backported by default labels Jul 11, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

@alexey-milovidov done. Pivoted to the root cause: the invariant is now enforced at ColumnArray construction (chassert that offsets are monotonic), so a producer that builds an inconsistent column aborts at its own stack in debug/sanitizer builds instead of deep in a consumer. chassert is a no-op in release, so release keeps only the existing O(1) last-offset check.

Dropped the getExtremes guard and the hand-built test. The producer of the inconsistent offsets is not deterministically reproducible after extensive attempts (sequential replay of the fuzzer sequence, concurrent insert/DDL races, direct construction), so this assertion is what will capture the real producer's stack the next time a fuzzer hits it, rather than an artificial test.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? No. The malformed-column producer is not deterministically reproducible after extensive attempts (sequential fuzzer replay, concurrent insert/DDL races, direct construction). Mechanism proven analytically: a non-monotonic-offset ColumnArray(Nullable) reaching getExtremes reads the nested null map OOB.
b Root cause explained? Yes. ColumnArray offsets are cumulative array sizes and must be monotonic. The ctor checked only offsets.back() == getData().size(), not monotonicity; a column with offsets[i] < offsets[i-1] passes, then offsetAt(i) > offsets[i] makes consumers index the nested column (ColumnNullable null map) out of bounds.
c Fix matches root cause? Yes. Enforces the monotonicity invariant at the single point of trust (construction) so offsets are always consistent, per the maintainer direction. Not a consumer-side band-aid.
d Test intent preserved / new tests? The prior hand-built column test is removed (a fabricated corrupt column proves nothing about a real producer). No new artificial test added; the ctor chassert is what captures the real producer's stack in fuzzer/sanitizer CI.
e Demonstrated both directions? Positive: normal Array(Nullable) + tuple extremes compute correctly and match references (00254_tuple_extremes), no false abort, across array/extremes/nullable stateless runs (0 chassert aborts). Negative direction is the fuzzer path itself, which will now abort at the producer.
f Fix general, not narrow? Yes. The invariant covers every consumer of a ColumnArray (compareAt, getExtremes, get, ...) and every nested type, not just the one getExtremes/Nullable manifestation.
g Generalizes across inputs/wrappers? Yes. Enforced on the offsets column itself, independent of nested element type (Nullable, LowCardinality, plain, etc.).
h Backward compatible? Yes. chassert is a no-op in release builds; no release behavior change, no format/setting change. Debug/sanitizer builds gain an abort at the producer, which is the intent.
i Invariants/contracts preserved? Yes. Codifies the documented ColumnArray offsets-are-cumulative-sizes invariant alongside the existing O(1) last-offset check; no other contract touched.

Session id: cron:clickhouse-worker-slot-1:20260710-234900

Comment thread src/Columns/ColumnArray.cpp Resolved
The monotonicity chassert and the last-offset consistency check were gated
behind !data->empty(), so a malformed column with empty nested data bypassed
both: offsets = [1] with data->size() == 0 (last_offset != data->size()), or
offsets = [1, 0] (non-monotonic, last_offset == 0 == data->size()). Consumers
then walk the empty nested column via sizeAt(0) / compareAt.

Key the validation off !offsets_concrete->empty() && data instead. The
empty-nested-data case is accepted only when last_offset == 0 and offsets stay
non-decreasing; a positive last offset over empty data is rejected by the
existing last-offset check. Release cost is unchanged (the monotonicity walk
stays chassert-only; the last-offset check is O(1)).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? N/A for this follow-up. The malformed producer is not deterministically reproducible (why this is a construction-time invariant, not a consumer guard). The bypass the bot found is verified by inspection of the gate condition.
b Root cause explained? The validation block was gated by !data->empty(), so empty nested data skipped BOTH the last-offset check and the monotonicity assert. Shapes offsets=[1] (size 0) and offsets=[1,0] (size 0) then constructed; sizeAt(0)/compareAt walk the empty nested column.
c Fix matches root cause? Yes. Gate keyed off !offsets_concrete->empty() && data instead of && !data->empty(), so the checks run whenever there are offsets. Empty nested data is accepted only when last_offset == 0 and offsets are non-decreasing.
d Test intent preserved? Yes. Per the root-cause directive no artificial hand-built column test is added; the invariant is enforced at the single point of trust (construction). Well-formed construction across many shapes is exercised by the existing suite.
e Demonstrated both directions? Well-formed shapes (empty arrays, empty-data array columns offsets=[0,0,0], Array(Nullable), getExtremes over empty arrays) construct/run cleanly on the rebuilt debug binary. The two malformed empty-data shapes now hit the last-offset throw / monotonicity chassert respectively.
f Fix general, not a narrow patch? Yes. The single construction site covers all ColumnArray creation; no sibling path duplicates the gate.
g Generalizes across inputs? Offset shapes enumerated: [] (skipped, no offsets), [0]/[0,0] empty data (accepted), [1] empty data (throws 0!=1), [1,0] empty data (monotonicity chassert), non-decreasing with matching data (accepted). Each constructs or aborts correctly.
h Backward compatible? Yes. No format/setting/wire change. Release behavior for well-formed columns is unchanged; only malformed empty-data columns are now caught (previously undefined out-of-bounds behavior).
i Invariants preserved? Yes. Enforces offsetAt(i) <= offsets[i] <= data.size() for all rows including the empty-data path (last_offset==0 required), on all construction paths.

Session id: cron:clickhouse-worker-slot-2:20260711-010800

The previous change (validate whenever offsets are non-empty, dropping the
!data->empty() guard) broke arrayRandomSample and the many array functions that
use the pre-size-then-fill idiom: they build the ColumnArray with an empty
nested column (cloneEmpty) and a pre-sized-but-unfilled offsets column
(ColumnUInt64::create(rows)), then populate both afterwards via
getData()/getOffsets(). At construction the offsets hold uninitialized values,
so the last-offset consistency check (data->size() != last_offset) raised a
spurious LOGICAL_ERROR (02874_array_random_sample Fast test failure), and the
monotonicity chassert could trip on the same garbage.

The constructor cannot tell that transient pre-size state apart from a truly
malformed empty-data column, so it must not validate offsets while the nested
data is still empty. Gate both the last-offset check and the monotonicity
chassert on !data->empty(): they run once the column is fully built, which is
exactly when non-monotonic offsets would cause out-of-bounds reads in consumers
(compareAt, getExtremes). This keeps the root-cause invariant enforcement for
the case that matters while leaving the common construction idiom intact.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Re the empty-nested-data concern (clickhouse-gh[bot], r3562802085): the previous commit (51b038b) tried exactly that — validate whenever offsets are non-empty, dropping the !data->empty() guard. That broke the Fast test (02874_array_random_sample, LOGICAL_ERROR Code 49) and it is not fixable by keying off !offsets_concrete->empty().

Root cause: arrayRandomSample (and many array functions) use the pre-size-then-fill idiom — they construct the ColumnArray with an empty nested column (cloneEmpty()) and a pre-sized-but-unfilled offsets column (ColumnUInt64::create(input_rows_count)), then populate both afterwards via getData() / getOffsets():

auto col_res_data = col_array->getDataPtr()->cloneEmpty();       // empty
auto col_res_offsets = ColumnUInt64::create(input_rows_count);   // pre-sized, uninitialized
auto col_res = ColumnArray::create(std::move(col_res_data), std::move(col_res_offsets));
auto & res_offsets = col_res->getOffsets();                      // filled after construction

At the constructor call the offsets hold uninitialized garbage (ColumnUInt64::create(n) reserves + advances c_end without zeroing), so they are neither last_offset == 0 nor guaranteed non-decreasing. The bot's proposed gate (!offsets_concrete->empty(), accept empty data only when last_offset == 0 and non-decreasing) still fires on this legitimate transient state — it just moves the spurious failure from the last-offset check into the accept-condition.

The constructor genuinely cannot distinguish "transient pre-size garbage + empty data" from "final malformed column + empty data": while the nested data is empty the offsets carry no trustworthy information. That is why master has always gated on !data->empty() — a deliberate accommodation of this pervasive construction pattern, not an oversight.

So this commit (6ad0271) restores the !data->empty() gate. The root-cause monotonicity chassert and the last-offset consistency check both run once the column is fully built (data populated) — which is exactly when non-monotonic offsets would cause the out-of-bounds reads in compareAt/getExtremes that this PR targets. The empty-data window carries no offset semantics to enforce.

Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. On head 51b038b, SELECT arrayRandomSample([1,2,3,4], 2) raised Code 49 LOGICAL_ERROR: offsets_column has data inconsistent with nested_column in the Fast test (02874, PR #109212 only, 0 master, 0 other PRs).
b Root cause explained? Yes. arrayRandomSample builds the ColumnArray with empty nested data + a pre-sized unfilled offsets column, filling offsets after construction. 51b038b dropped the !data->empty() guard, so the last-offset check (and monotonicity chassert) ran on the uninitialized offsets → spurious LOGICAL_ERROR.
c Fix matches root cause? Yes. Restore the !data->empty() gate: validate only once the nested data is populated, i.e. when offsets are meaningful. The bot's !offsets_concrete->empty() alternative cannot work — pre-size garbage is neither last_offset==0 nor sorted.
d Test intent preserved / new tests added? Yes. The monotonicity invariant enforcement (this PR's purpose) is unchanged for the case that matters (data present → offsets built → OOB in consumers). No test weakened; no artificial test per the root-cause directive.
e Both directions demonstrated? Yes. Head 51b038b (Build ID 68eef744): 02874 path aborts. Head 6ad0271 (Build ID b455fd6c): arrayRandomSample (scalar/multi-row/nested/higher-sample/K=0/empty-array) + max/min over array columns containing empties all construct + run cleanly.
f Fix is general across code paths? Yes. The !data->empty() gate is the single ColumnArray construction validation point; it covers every producer using the pre-size-then-fill idiom (238 ColumnArray::create sites), not just arrayRandomSample.
g Fix generalizes across inputs? Yes. Verified across nested types (Int/String/Array), empty arrays, empty-data columns, multi-row, K=0 and K>size. The gate is type-agnostic (keys off nested-data emptiness, not element type).
h Backward compatible? Yes. Restores master's long-standing !data->empty() behavior; no setting/format/on-disk change; release path keeps the O(1) last-offset check on fully-built columns.
i Invariants and contracts preserved? Yes. offsetAt(i) <= offsets[i] <= data.size() is enforced on all fully-built columns (data present). The empty-data window carries no offset semantics, so there is no invariant to enforce there; consumers never read the nested column when it is empty.

Session id: cron:clickhouse-worker-slot-3:20260711-013700

Comment thread src/Columns/ColumnArray.cpp Resolved
A chassert is a no-op under !DEBUG_OR_SANITIZER_BUILD, so a directly
constructed ColumnArray with non-monotonic offsets (e.g. {2,1,3} with
matching data size) passed construction in release and later read the
nested column out of bounds in compareAt / getExtremes. Replace the
chassert with a real throw so the invariant holds in release too.

The check stays inside the !data->empty() gate: the pre-size-then-fill
idiom (arrayRandomSample and many array functions) constructs with an
empty nested column and unfilled offsets, then populates both afterwards,
so it is skipped as before. Every non-empty-data construction already
runs the O(1) last-offset check here, so it always presents finalized
offsets - the added is_sorted pass can only fire on a genuinely
malformed column.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes for the fix's own contract: constructing a ColumnArray with offsets={2,1,3}, data.size()==3 deterministically throws LOGICAL_ERROR at construction (verified via a gtest that builds exactly that column). The original producer of the inconsistent column remains non-deterministic (fuzzer-only), unchanged from before.
b Root cause explained? Offsets are cumulative array sizes and must be non-decreasing. The ctor checked only offsets.back()==data.size(), not monotonicity, so a decreasing-offset column passed; offsetAt(i) then exceeds offsets[i] and compareAt/getExtremes read the nested column OOB. The prior chassert was a no-op in release, so the invariant was not actually enforced there.
c Fix matches root cause? Yes. The invariant is enforced at the single point of trust (construction) as a real throw, so a malformed column is rejected in release as well as aborting in debug/sanitizer.
d Test intent preserved / new tests? 02874_array_random_sample (the pre-size-then-fill path) continues to pass — the check stays inside the existing !data->empty() gate. No artificial hand-built-column test is committed (per the earlier review that such a test is pointless); the runtime throw is the enforcement.
e Demonstrated both directions? Yes. Malformed non-monotonic column → throws (verified). Well-formed columns, empty arrays, empty-data columns, arrayRandomSample (scalar/multi-row/empty/K=0), and max/min extremes over Array(Nullable) all construct and run cleanly on a Build-ID-verified debug binary (f1ed7d44).
f Fix general, not a narrow patch? Yes. The check is at ColumnArray construction — the single choke point through which all ~240 ColumnArray::create sites pass — not at one consumer.
g Generalizes across inputs? Offset shapes enumerated: [] (empty offsets, skipped), [0]/[0,0] (last_offset 0, accepted when data empty), [1] + empty data (transient, skipped), [1,0] / [2,1,3] (non-monotonic, rejected once data present), valid non-decreasing (accepted). Invariant offsetAt(i) <= offsets[i] <= data.size() holds on all paths.
h Backward compatible? No format/setting/wire change. A malformed column that previously silently passed now throws — that is the intended correctness fix, and no valid column's behavior changes.
i Invariants/contracts preserved? Yes. The pre-size-then-fill transient state (empty nested data + unfilled offsets) is deliberately still skipped; the check runs only on the finalized column, exactly where the existing last-offset check already ran.

Session id: cron:clickhouse-worker-slot-0:20260711-023500

Comment thread src/Columns/ColumnArray.cpp Resolved
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 07b0de9

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stress test (arm_asan_ubsan) / Not-ready Set is passed as the second argument for function 'A' (STID 0250-4e52) chronic trunk LOGICAL_ERROR (IN-family set-build race), 217 PRs / 31 master / 30d — not PR-caused (this PR only touches ColumnArray construction) #107924 (external, open) / #109722 (ours, open)
CH Inc sync — CH Inc sync (private, not actionable)

Session id: cron:our-pr-ci-monitor:20260711-080000

@groeneai

groeneai commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 2830af2

CI is fully finished and clean: 175 check-runs, 0 queued/in_progress, Config Workflow and
Finish Workflow both green, last check completed 2026-08-08T04:33:42Z. Counted by conclusion:
152 success, 23 skipped, and zero with any other conclusion.

Check / test Reason Owner / fixing PR
none no failures on this commit not applicable

Checked at the sub-result level rather than only by job verdict, because a Post Hooks failure rides on
a green job: all Build (*) check-runs are green with no failing sub-result. In particular the docker
image-pull registry reset ledgered earlier on this PR did not recur.

Session id: cron:our-pr-ci-monitor:20260808-043000

…solute-offsets encoding

Addresses the AI review blocker: a monotonic absolute-offsets stream (e.g. `[1]`)
with an empty elements stream passed both the monotonicity check and the
offsets-vs-elements guard (which had an unconditional empty-elements carveout),
returning a `ColumnArray` whose `last_offset` exceeds the elements size, so
consumers like `getExtremes` / `compareAt` could read past the end.

The carveout stays intact for the sizes encoding (`position_independent_encoding`),
where an empty elements column is how a column of a `Nested` type added by
`ALTER` reads parts written before that `ALTER`. The absolute-offsets encoding
always writes the elements next to the offsets, so there it now throws
`INCORRECT_DATA`.

Co-Authored-By: Claude Fable 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing f936ecbcf with master 8cb46d93b (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

⚠️ Significant changes: compile time of recompiled translation units.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 690.64 MiB 687.62 MiB -3.02 MiB (-0.44%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units ⚠️

480 translation units recompiled, 503 s compile time in total, 8 of them have a recent master baseline.

Translation units without a recent master baseline:

  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/Passes/PassBuilder.cpp: 25.1 s
  • contrib/ai-sdk-cpp-cmake/__/ai-sdk-cpp/src/providers/base_provider_client.cpp: 7.3 s
  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp: 6.6 s
  • contrib/wasmedge-cmake/__/wasmedge/lib/validator/component_validator.cpp: 6.5 s
  • contrib/vectorscan-cmake/__/vectorscan/src/nfa/limex_compile.cpp: 6.1 s
  • contrib/rocksdb-cmake/__/rocksdb/table/block_based/block_based_table_reader.cc: 5.8 s
  • contrib/google-cloud-cpp-cmake/__/google-cloud-cpp/google/cloud/storage/parallel_upload.cc: 5.8 s
  • contrib/google-cloud-cpp-cmake/__/google-cloud-cpp/google/cloud/storage/internal/rest/stub.cc: 5.6 s
  • contrib/rocksdb-cmake/__/rocksdb/db/write_batch.cc: 5.5 s
  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp: 5.4 s
  • contrib/wasmedge-cmake/__/wasmedge/lib/executor/instantiate/component/component_export.cpp: 5.3 s
  • contrib/vectorscan-cmake/__/vectorscan/src/nfagraph/ng_som.cpp: 5.2 s
  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/ObjectYAML/ELFEmitter.cpp: 5.2 s

Job report

@groeneai

groeneai commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - e89cc5d

CI is fully finished on the new head: 175 check-runs, 0 queued/in_progress, Config Workflow and
Finish Workflow both green, last check completed 2026-08-08T19:42:20Z. By conclusion: 151
success, 23 skipped, 1 failure.

Check / test Reason Owner / fixing PR
AST fuzzer (amd_debug, targeted) / Logical error: Bad cast from DB::ColumnNothing to DB::ColumnVector<char8_t> (STID 1499-2747) trunk bug in array-lexicographic comparison, not this diff #113609 (ours, open)

On the attribution: the whole abort path is in FunctionsComparison.h - assert_cast at
FunctionsComparison.h:1485 inside executeArrayLexicographicEqualityImpl, reached from
executeArray / executeImpl for notEquals. No serialization frame appears in the trace, so this
head's change to SerializationArray::deserializeBinaryBulkWithMultipleStreams is not on it. The
fuzzed query compares against arrayMap(x -> (x + NULL), range(...)), whose element type is
Nothing - exactly the case #113609 fixes. Over 30 days the same STID has 22 distinct carrier PRs,
which matches a trunk defect rather than anything specific to this branch.

FunctionsComparison.h at this head is not yet the fixed revision (blob 7a67b2051ff9 here vs
d2ea8449a34c on #113609), so the failure predates the fix rather than surviving it.

Session id: cron:our-pr-ci-monitor:20260808-203000

@groeneai

groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - f936ecb

CI is fully finished and clean on this head: 175 check-runs, 0 queued/in_progress, Config Workflow
and Finish Workflow both green, Mergeable Check and CH Inc sync green, last check completed
2026-08-09T08:05:55Z. By conclusion: 152 success, 23 skipped, and zero with any other conclusion.

Check / test Reason Owner / fixing PR
none no failures on this commit not applicable

Checked at the sub-result level as well, not only by job verdict, because a Post Hooks failure can
ride on a green job: CIDB reports 0 FAIL/ERROR rows for this commit sha. The AST fuzzer (amd_debug, targeted) Bad cast from DB::ColumnNothing row ledgered on the previous head
e89cc5db5b73 (owner #113609, ours) did not recur here, and neither did the docker image-pull
registry reset ledgered earlier on this PR (owner #113611, ours).

This head is a master merge pushed by the reviewer, so nothing was pushed from my side for it.

Session id: cron:our-pr-ci-monitor:20260809-090000

@alexey-milovidov alexey-milovidov 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.

Now good.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 12, 2026
Merged via the queue into ClickHouse:master with commit 1943298 Aug 12, 2026
179 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 12, 2026
@CurtizJ CurtizJ added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Sep 8, 2026
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 9, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 9, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 9, 2026
Backport #109212 to 26.6: Verify array offsets read as absolute values, not only in the Native format
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 9, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 9, 2026
Backport #109212 to 26.7: Verify array offsets read as absolute values, not only in the Native format
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 11, 2026
…lute values, not only in the Native format
PedroTadim added a commit that referenced this pull request Sep 11, 2026
Backport #109212 to 26.3: Verify array offsets read as absolute values, not only in the Native format
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 18, 2026
…lute values, not only in the Native format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants