Repository navigation
Conversation
ColumnString::filter (both the const and in-place overloads) handed
`offsets` and `chars` straight to filterArraysImpl / filterArraysImplInPlace
without checking that they are consistent. The SIMD fast path in
filterArraysImplGeneric (ColumnsCommon.cpp) trusts `offsets` to compute chunk
sizes: for a full-passing 64-row chunk it does
chunk_size = offsets_pos[63] - offsets_pos[-1], then resize + memcpy that many
bytes. If a corrupt column arrives with offsets.back() != chars.size() (offsets
overshoot chars, or non-monotonic), chunk_size is bogus and the memcpy runs off
the end of the destination/source buffer, an out-of-bounds write.
Observed in CI as a SEGV ("address not mapped") with the stack
__asan_memcpy
ColumnsCommon.cpp ResultOffsetsBuilder::insertChunk<64> / filterArraysImpl<char8_t>
ColumnString::filter -> ColumnNullable::filter -> FilterDescription::filter
-> FilterTransform::doTransform
when filtering a nullable String column produced by the parquet reader on a
metadata-cache-hit path. The corrupt column is produced upstream; this change
does not fix the upstream producer, it converts the silent out-of-bounds write
into a clean INCORRECT_DATA exception so the corruption fails safely and is
diagnosable instead of crashing (or silently corrupting memory) in release
builds.
This mirrors the invariant the ColumnString copy constructor already enforces
(offsets.back() == chars.size()) and the guard recently added to the sibling
ColumnString::insertRangeFrom path.
Adds unit tests that build a ColumnString whose offsets overshoot chars and
assert filter() throws INCORRECT_DATA instead of reading/writing out of bounds
(the large-overshoot case is an ASan heap-buffer-overflow without the guard),
plus a positive test that a consistent column still filters correctly.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-5:20260702-124200 |
|
cc @Avogar @CurtizJ @davenger could you review this? It adds an O(1) consistency guard to |
|
Workflow [PR], commit [a9d41cf] Summary: ✅
AI ReviewSummaryThis PR adds an Findings❌ Blockers
Tests
Final Verdict❌ Not ready to merge: LLVM Coverage ReportMeasured on commit a9d41cf.
Changed lines: Changed C/C++ lines covered: 58/59 (98.31%) · Uncovered code |
| /// Enforce the ColumnString invariant (offsets.back() == chars.size(), same as the copy | ||
| /// constructor) before filterArraysImpl trusts `offsets` to size its memcpys; a violated | ||
| /// invariant would otherwise read/write out of bounds instead of failing cleanly. | ||
| if (offsets.back() != chars.size()) |
There was a problem hiding this comment.
filterArraysImpl and filterArraysImplInPlace rely on more than offsets.back() == chars.size(): copy_array subtracts every offset from the previous one. A corrupt column like offsets = [4, 2, 12] still passes this new check, but filtering the second row makes arr_size = 2 - 4, which underflows and drives a huge resize/memcpy in both paths. Since the upstream producer is still unknown, the guard here needs to reject non-monotonic offsets too, and the new tests should cover the decreasing/dipping cases the same way insertRangeFrom already does.
CI finish ledger — 7ce9c3aEvery 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
Note: Session id: cron:our-pr-ci-monitor:20260702-173000 |
CI finish ledger — 7ce9c3aEvery 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:20260703-043000 |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 53/54 (98.15%) · Uncovered code |
CI finish ledger - 8ae89d3Every failure below has an owner: a fixing PR, or a full-effort fix task whose
Session id: cron:our-pr-ci-monitor:20260729-083000 |
The positive control filtered every third row, so no 64-row block ever passed in full and the all-pass chunk branch of `filterArraysImplGeneric`, whose unchecked `chunk_size` arithmetic the guard protects, never ran, even though the comment claimed it did. The mask now passes rows 0-63 as a block, then every third row, then leaves a partial trailing chunk, so the all-pass chunk, the per-row branch inside a chunk and the scalar tail are all covered, and the test asserts the resulting `chars` size as well as the row contents. The two overshoot tests differed only in magnitude and killed the same mutant. They are now one test, using the magnitude that actually leaves the allocation (ASan: `heap-buffer-overflow`, read of 262400 bytes past a 1024-byte region). The new mirror case covers a last offset below `chars.size()`, which a guard written with `>` instead of `!=` would let through. The comments state the constructed layout and the invariant instead of repeating the CI stack and the ASan narrative from the PR description, and wrap literal class and function names in inline code. Co-Authored-By: Claude Opus 5 <[email protected]>
Build profile diff (arm_release)Comparing Binary sizes
The official master build is compiled with Object file sizes
|
| Object file | Master | PR | Δ |
|---|---|---|---|
src/CMakeFiles/dbms.dir/Processors/QueryPlan/Optimizations/Cascades/Rules/AggregationPushdown.cpp.o |
new | 278.38 KiB | +278.38 KiB |
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.
Compile time of recompiled translation units
48 translation units recompiled, 529 s compile time in total, 48 of them have a recent master baseline.
Related: #107355
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a possible out-of-bounds read in
ColumnString::filterwhen aStringcolumn arrives with a last offset that does not match the size of itscharsarray. Filtering such a column now raisesINCORRECT_DATAinstead of copying past the end of the buffer.Description
ColumnString::filter(both theconstand in-place overloads) passedoffsetsandcharsstraight tofilterArraysImpl/filterArraysImplInPlacewithout checking that the two are consistent. The SIMD fast path infilterArraysImplGeneric(ColumnsCommon.cpp) sizes its copies fromoffsetsalone: for a full-passing 64-row chunk it computeschunk_size = offsets_pos[63] - offsets_pos[-1], then doesresize+memcpyof that many bytes. A last offset past the end ofcharstherefore copies from beyond the source buffer.This surfaced in CI as a SEGV (
address not mapped to object) inResultOffsetsBuilder::insertChunk<64>, reached fromFilterTransform::doTransformthroughColumnNullable::filter, while filtering a nullableStringcolumn produced by the Parquet reader on a metadata-cache hit. That producer is not deterministically reproducible and the offsets of the corrupt column are not recorded, so this PR does not touch it. It validates, where the corruption turns into memory unsafety, the invariant theColumnStringcopy constructor already enforces (offsets.back() == chars.size()), the same guard #107355 added to the siblingColumnString::insertRangeFrompath.Scope: the check is the O(1) endpoint invariant, so well-formed columns pay one comparison per
filtercall. It deliberately does not verify that the intermediate offsets are monotonic, which would need a per-row scan on one of the hottest paths in the engine, so a column whose offsets dip in the middle whileoffsets.back() == chars.size()still reaches the helper.ColumnString::sizeAtalreadychasserts that property, but the filtering helpers do their own offset arithmetic and never reach it, so if you would rather have sanitizer builds reject the whole class here, I will move the scan underDEBUG_OR_SANITIZER_BUILD.Validation: the new gtests reproduce the unguarded defect (ASan
heap-buffer-overflow, read of 262400 bytes past a 1024-byte region) and pass with the guard; a consistent column exercising the all-pass chunk, the per-row branch and the scalar tail still filters correctly.Workflow [PR]
Sync PR [sync-upstream/pr/109184]