Repository navigation
Verify array offsets read as absolute values, not only in the Native format - #109212
alexey-milovidov merged 14 commits into
Conversation
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-6:20260702-175800 |
|
cc @Algunenano @CurtizJ could you review this? It adds an O(rows) offsets-consistency guard to |
|
Workflow [PR], commit [f936ecb] Summary: ✅
AI ReviewSummaryThis 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
Changed lines: Changed C/C++ lines covered: 78/80 (97.50%) · Uncovered code |
CI finish ledger — 32695b1CI is complete on this head. No failed tests; all aggregators green (Finish Workflow, Mergeable Check, CH Inc sync all 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 |
|
@groeneai, this is incorrect. The fix should be in the root cause - to make offsets always consistent. |
|
@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 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]>
32695b1 to
e69b71c
Compare
|
@alexey-milovidov done. Pivoted to the root cause: the invariant is now enforced at Dropped the |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-1:20260710-234900 |
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]>
Pre-PR validation gate (click to expand)
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]>
|
Re the empty-nested-data concern ( Root cause: 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 constructionAt the constructor call the offsets hold uninitialized garbage ( 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 So this commit (6ad0271) restores the Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-3:20260711-013700 |
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]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-0:20260711-023500 |
CI finish ledger — 07b0de9Every 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
Session id: cron:our-pr-ci-monitor:20260711-080000 |
CI finish ledger - 2830af2CI is fully finished and clean: 175 check-runs, 0 queued/in_progress,
Checked at the sub-result level rather than only by job verdict, because a 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]>
Build profile diff (arm_release)Comparing Binary sizes
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
|
CI finish ledger - e89cc5dCI is fully finished on the new head: 175 check-runs, 0 queued/in_progress,
On the attribution: the whole abort path is in
Session id: cron:our-pr-ci-monitor:20260808-203000 |
CI finish ledger - f936ecbCI is fully finished and clean on this head: 175 check-runs, 0 queued/in_progress,
Checked at the sub-result level as well, not only by job verdict, because a 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 |
Backport #109212 to 26.6: Verify array offsets read as absolute values, not only in the Native format
…s, not only in the Native format
Backport #109212 to 26.7: Verify array offsets read as absolute values, not only in the Native format
…lute values, not only in the Native format
Backport #109212 to 26.3: Verify array offsets read as absolute values, not only in the Native format
…lute values, not only in the Native format
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Rejects non-monotonic
Arrayoffsets on every read path that decodes them as absolute values, instead of only in theNativeformat. A corruptsetskip index granule previously passed unchecked and was then read out of bounds.Description
SerializationArray::deserializeOffsetsBinaryBulkalready refuses decreasing offsets, but the check was gated onsettings.native_format, which onlyNativeReaderandNativeWriterever 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
Nativeis not its only user. Bothsetskip index granule readers setposition_independent_encoding = false, so a granule is decoded as absolute offsets with no check;MergeTreeIndexGranuleSet::deserializeBinarythen callsgetExtremeson 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_encodingand 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;Nativekeeps 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::createColumnand fills it in place, so the constructor never sees these offsets. This closes an unchecked ingress; it does not identify the producer behind the reportedExtremesTransformextremes, 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
getExtremesread out of bounds over non-monotonic offsets. Related: #112504 covers the constructor-side half.Version info
26.7.7.57,26.6.5.84,26.3.33.48