Skip to content

Extend COW-safe IColumn::mutate sweep to deserialize and patch-apply paths - #109105

Merged
alexey-milovidov merged 6 commits into
masterfrom
cow-safe-merge-read-deserialize-double-free
Jul 5, 2026
Merged

alexey-milovidov merged 6 commits into
masterfrom
cow-safe-merge-read-deserialize-double-free

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jul 2, 2026 •

Copy link
Copy Markdown
Member

Related: #107451

MergeTreeSequentialSource::generate finalizes merge output columns with an in-place shrinkToFit that reallocates their buffers. Under ASan this keeps producing heap-use-after-free / double-free reports during horizontal merges — the latest (MasterCI report below) is a double-free at shrinkToFit on a plain UInt64 column deserialized from disk during a background horizontal merge of plain (system) tables. That signature means a merge output column shares an underlying buffer with another owner through a path that bypasses copy-on-write reference counting.

PR #107451 hardened the generate finalize sites themselves (and the follow-up sweep in 36b1d340ecc covered several readers). This continues that sweep for the read/deserialize and patch-apply paths that feed those columns, replacing the remaining in-place mutations of potentially-shared columns with IColumn::mutate (clone only when use_count > 1; a no-op for the common uniquely-owned case, so the hot path keeps the same cost):

  • ISerialization::deserializeBinaryBulkWithMultipleStreams appended freshly deserialized data into column via assumeMutable. When column was already placed into the substreams cache by an earlier substream read, this mutated shared data in place.
  • ISerialization::insertDataFromCachedColumn appended cached rows into a result_column that may be shared with the substreams cache, via assumeMutable.
  • applyPatchesToBlockRaw / applyPatchesToBlockCombined applied patches in place via assumeMutableRef().updateInplaceFrom on a result column that may still be referenced elsewhere.

The crash is intermittent and could not be reproduced locally, so this is targeted copy-on-write hardening on the paths that produce merge output columns rather than a confirmed fix for that exact report; the ASan CI is the validation.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=c794d5be5e1c4c2de860253ce712bdffa9a7e50e&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20distributed%20plan%2C%20sequential%2C%201%2F2%29

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

Not required (CI Fix or Improvement).

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.7.1.532 (included in 26.7 and later)

…y paths

`MergeTreeSequentialSource::generate` finalizes merge output columns with an
in-place `shrinkToFit` that reallocates their buffers. Under ASan this keeps
producing `heap-use-after-free` / `double-free` reports during horizontal
merges (the latest is a `double-free` at `shrinkToFit` on a plain `UInt64`
column deserialized from disk), which means a merge output column shares an
underlying buffer with another owner via a path that bypasses copy-on-write
reference counting.

PR #107451 hardened the `generate` finalize sites themselves; this continues
that sweep for the read/deserialize and patch-apply paths that feed those
columns, replacing the remaining in-place mutations of potentially-shared
columns with `IColumn::mutate` (clone only when `use_count > 1`, a no-op for
the common uniquely-owned case):

- `ISerialization::deserializeBinaryBulkWithMultipleStreams` appended freshly
  deserialized data into `column` via `assumeMutable`; when `column` was
  already placed into the substreams cache by an earlier substream read this
  mutated shared data in place.
- `ISerialization::insertDataFromCachedColumn` appended cached rows into a
  `result_column` that may be shared with the substreams cache via
  `assumeMutable`.
- `applyPatchesToBlockRaw` / `applyPatchesToBlockCombined` applied patches
  in place via `assumeMutableRef().updateInplaceFrom` on a result column that
  may still be referenced elsewhere.

The crash is intermittent and could not be reproduced locally, so this is
targeted copy-on-write hardening on the paths that produce merge output
columns rather than a confirmed fix for that exact report; the ASan CI is the
validation.

CI report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=c794d5be5e1c4c2de860253ce712bdffa9a7e50e&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20distributed%20plan%2C%20sequential%2C%201%2F2%29

Related: #107451

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [21adeab]

Summary: ✅


AI Review

Summary

This PR extends the deserialize-side and patch-apply copy-on-write hardening from the earlier merge-read fix: the generic cached-column append helper now clones before mutating shared state, the rows_offset > 0 cache-hit paths in the size readers and Variant discriminators do the same, and the patch-apply fast paths stop updating shared columns in place. I re-checked the current diff against the full touched code and the prior review threads; the concrete cache-aliasing holes raised earlier now look covered, and I do not have any new blocking findings in the current revision.

Final Verdict

✅ No blocking findings in the current revision.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 2, 2026
alexey-milovidov and others added 2 commits July 2, 2026 04:36
…reams

The previous commit changed `ISerialization::deserializeBinaryBulkWithMultipleStreams`
to `auto mutable_column = IColumn::mutate(std::move(column))`. `std::move(column)`
empties `column` immediately, and it was only restored via `column = std::move(mutable_column)`
on the success path. When `deserializeBinaryBulk` threw (e.g. `MEMORY_LIMIT_EXCEEDED`),
`column` was left moved-from (null), whereas the old `assumeMutable` path always left it
valid. Callers that inspect the column after catching the exception then dereferenced a
null `ColumnPtr`.

This is what broke the `StringSerialization.IncorrectStateAfterMemoryLimitExceeded` unit
test across all sanitizer variants (`asan_ubsan` reported UB in `intrusive_ref_counter`;
`tsan`/`msan`/`llvm_coverage` segfaulted).

Fix: reassign `column` to the (possibly cloned) column up front and mutate it in place via
`assumeMutableRef`, so `column` stays a valid unique owner even if `deserializeBinaryBulk`
throws. `IColumn::mutate` still clones only when the column is shared (a no-op for the
common uniquely-owned case), preserving the copy-on-write hardening.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109105&sha=3be6dbd3c4a1386d1ee43d059b7b2fcc8dbb7da4&name_0=PR&name_1=Unit%20tests%20%28asan_ubsan%29

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The previous sweep made `ISerialization::insertDataFromCachedColumn` copy-on-write safe
for the zero-`rows_offset` cache append, but the `rows_offset > 0` cache-hit branches in
`SerializationArrayOffsets::deserializeBinaryBulkWithMultipleStreams` and
`SerializationStringSize::deserializeBinaryBulkWithSizeStream` still appended cached rows
into `column` (and later compacted the `ColumnUInt64` in place) via `assumeMutable`.

`column` can alias `cached_column`: the same size substream may be read first with
`rows_offset == 0` — placing `column` itself into the substreams cache — and then re-read
in the same range with `rows_offset > 0`. In that case both the append and the in-place
compaction mutate storage still referenced by the cache, so the later `shrinkToFit` /
destruction path can still hit the same `heap-use-after-free` / `double-free`.

Clone `column` when shared via `IColumn::mutate` before the append; the subsequent
compaction then always runs on a uniquely-owned column (the cache path cloned it when
shared, and the fresh-read path caches a separate `cut()` copy). `IColumn::mutate` is a
no-op for the common uniquely-owned case, so the hot path keeps the same cost.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Pushed two follow-up commits (3be6dbd3c4a..8d775442717):

  1. 7651d65 Keep column valid on exception in deserializeBinaryBulkWithMultipleStreams — this fixes the CI failure. The switch to auto mutable_column = IColumn::mutate(std::move(column)) emptied column up front and only restored it via column = std::move(mutable_column) on the success path, so a throw inside deserializeBinaryBulk (e.g. MEMORY_LIMIT_EXCEEDED) left column moved-from (null) — the old assumeMutable path never did. That is exactly what broke StringSerialization.IncorrectStateAfterMemoryLimitExceeded across all sanitizer variants (asan_ubsan UB in intrusive_ref_counter; tsan/msan/llvm_coverage SIGSEGV). Fix: assign the (possibly cloned) column back to column up front and mutate via assumeMutableRef, so it stays a valid unique owner on the exception path while keeping the COW clone-if-shared behavior.

  2. 8d77544 Complete COW sweep for rows_offset size readers — addresses the AI-review blocker. SerializationArrayOffsets::deserializeBinaryBulkWithMultipleStreams and SerializationStringSize::deserializeBinaryBulkWithSizeStream still used assumeMutable on the rows_offset > 0 cache-hit path, where column can alias cached_column; now they clone via IColumn::mutate before the append so neither the append nor the in-place compaction touches cached storage.

Validated locally by building unit_tests_dbms (Debug) and running the StringSerialization suite — all 3 tests pass, including IncorrectStateAfterMemoryLimitExceeded (was a SIGSEGV before), and the broader serialization gtests show no regressions.

Note: insertDataFromCachedColumn still uses the move-out-then-restore-on-success shape, so it would also leave result_column null if insertRangeFrom throws mid-insert. It is not exercised by the failing test (cache is null there) and I left it untouched, but you may want the same assumeMutableRef treatment there for consistency.

`insertDataFromCachedColumn` still used the move-out-then-restore-on-success
shape: `auto mutable_result = IColumn::mutate(std::move(result_column))`
emptied `result_column` up front and only reassigned it via
`result_column = std::move(mutable_result)` on the success path. If
`insertRangeFrom` throws mid-append (e.g. `MEMORY_LIMIT_EXCEEDED` on a
cache-hit append), `result_column` is left moved-from (null), whereas the
pre-sweep `assumeMutable` path preserved a valid column.

This is the same exception-safety regression that was fixed in
`deserializeBinaryBulkWithMultipleStreams`. Apply the identical treatment
here: assign the (possibly cloned) column back to `result_column` first,
then mutate in place via `assumeMutableRef`, so `result_column` stays a
valid unique owner on the exception path while keeping the COW
clone-if-shared behavior.

This cache-hit helper is used by `SerializationStringSize`,
`SerializationArrayOffsets`, `SerializationSparse`,
`SerializationVariantElement`, `SerializationMapKeyValue` and others, so the
regression affected all of them.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Pushed 54dbe3dd7ae to address the first AI-review blocker — the insertDataFromCachedColumn exception-safety note you flagged yourself ("you may want the same assumeMutableRef treatment there for consistency"):

  • insertDataFromCachedColumn (ISerialization.cpp:816) — now mirrors the deserializeBinaryBulkWithMultipleStreams fix at :282: result_column = IColumn::mutate(std::move(result_column)) is assigned back up front, then the append goes through result_column->assumeMutableRef().insertRangeFrom(...). If insertRangeFrom throws (e.g. MEMORY_LIMIT_EXCEEDED on a cache-hit append), result_column stays a valid unique owner instead of being left moved-from (null), while keeping the COW clone-if-shared behavior. Syntax-checked against the real build flags (clang++ -fsyntax-only, clean).

The second AI-review blocker (SerializationVariant.cpp:564,649-651, VariantDiscriminators cache-hit path) is left for your decision — it is pre-existing code this PR does not touch, so extending the sweep there is a scope call rather than a mechanical follow-up:

  • The alias the AI describes is: a rows_offset == 0 read stores col.getLocalDiscriminatorsPtr() itself in the cache (:607-608, not a cut() copy), so a later rows_offset > 0 cache-hit read on the same col has cached_column aliasing the discriminators, and the in-place assumeMutable() append at :564 / compaction at :649-651 then mutate cached storage — the same COW hole the size-reader commit closes.

  • A contained fix looks feasible via the non-const ColumnVariant::getLocalDiscriminatorsPtr overload, e.g. before the :564 append:

    auto & discr = col.getLocalDiscriminatorsPtr();
    discr = IColumn::mutate(std::move(discr));
    discr->assumeMutableRef().insertRangeFrom(*cached_column, cached_column->size() - num_read_rows, num_read_rows);

    but it reassigns ColumnVariant's internal discriminators WrappedPtr and should be validated against the rest of the Variant invariants (and ideally gets a focused test). I did not want to push a change to Variant deserialization internals in an untouched file ahead of your judgment, given you deliberately scoped the sweep to the size readers. Happy to implement it + add a gtest if you want it in this PR.

CI: the only red is Performance Comparison (arm_release, master_head, 1/6) → "Errors while building the report" — a report-builder infra flake (its all-query-metrics.tsv is corrupt: utf-8 codec can't decode byte 0xb5; the other 5 arm shards ran fine with only borderline bidirectional noise, 5 faster / 5 slower each near threshold). A COW-safe deserialize change cannot make the perf report builder fail to decode its own TSV.

alexey-milovidov and others added 2 commits July 5, 2026 06:28
Replace the "keep column valid on exception" shape from the previous commits
with the simpler and more readable move-based form:

    MutableColumnPtr mutable_column = IColumn::mutate(std::move(column));
    ... work with mutable_column ...
    column = std::move(mutable_column);

`IColumn::mutate` clones only when the column is shared (a no-op for the common
uniquely-owned case), which is what makes the append COW-safe; keeping the
`ColumnPtr` non-null across a throw is not worth the extra complexity. If
`deserializeBinaryBulk` / `insertRangeFrom` throws (e.g. `MEMORY_LIMIT_EXCEEDED`)
the caller may be left with a null column, which is acceptable — the read is
abandoned and the column discarded.

Applies to `ISerialization::deserializeBinaryBulkWithMultipleStreams`,
`ISerialization::insertDataFromCachedColumn`, and the `rows_offset` cache-hit
path of the `SerializationArrayOffsets` / `SerializationStringSize` size readers.

The `StringSerialization.IncorrectStateAfterMemoryLimitExceeded` gtest is updated
to tolerate a null column after `MEMORY_LIMIT_EXCEEDED`, still asserting that any
surviving column stays internally consistent.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…t path

`SerializationVariant::deserializeBinaryBulkWithMultipleStreams` still appended
cached discriminators in place via `assumeMutable` on the `rows_offset > 0`
cache-hit path. A prior `rows_offset == 0` read of the same substream caches
`col.getLocalDiscriminatorsPtr()` itself (not a `cut()` copy), so a later
`rows_offset > 0` cache hit on the same column has `cached_column` aliasing the
discriminators; the in-place append and the following in-place `rows_offset`
compaction then mutate storage still referenced by the cache — the same COW hole
the size readers close, and a candidate for the `heap-use-after-free` /
`double-free` this sweep targets.

Clone the discriminators via `IColumn::mutate` when shared before the append
(a no-op when uniquely owned), using the same move-based form as the size readers.

Adds `04504_variant_discriminators_cow_safe_rows_offset`, which reads a `Variant`
column and its subcolumns under `PREWHERE` on a wide part with tiny
`index_granularity` (`index_granularity_bytes = 0`) so the surviving rows are read
at `rows_offset > 0`. Under ASan a regression surfaces as
`heap-use-after-free` / `double-free`; the reference pins the correct results.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Pushed two follow-up commits (54dbe3dd7ae..21adeab47a4):

  1. 60fbf3a Simplify COW-safe deserialize sweep to the move-based form — reworks deserializeBinaryBulkWithMultipleStreams, insertDataFromCachedColumn, and the SerializationArrayOffsets / SerializationStringSize rows_offset cache-hit readers to the simpler, more readable shape from the review thread:

    MutableColumnPtr mutable_column = IColumn::mutate(std::move(column));
    // work with mutable_column
    column = std::move(mutable_column);

    This intentionally drops the "keep the ColumnPtr non-null across a throw" contract from 7651d65/54dbe3dd. IColumn::mutate still clones only when the column is shared (a no-op for the common uniquely-owned case), which is what makes the append COW-safe. If deserializeBinaryBulk / insertRangeFrom throws (e.g. MEMORY_LIMIT_EXCEEDED) the caller may be left with a null column — that is acceptable: the read is abandoned and the column discarded, and it keeps the code simple. The StringSerialization.IncorrectStateAfterMemoryLimitExceeded gtest is updated to tolerate a null column after MEMORY_LIMIT_EXCEEDED while still asserting any surviving column stays consistent (all 3 StringSerialization gtests pass under ASan).

    This supersedes the AI-review "still moves the only ColumnPtr into IColumn::mutate" blocker: exception-safety of the pointer is deliberately not pursued.

  2. 21adeab Extend COW-safe sweep to SerializationVariant discriminators cache-hit path — addresses the remaining blocker. The rows_offset > 0 cache-hit path appended cached discriminators in place, while a prior rows_offset == 0 read caches col.getLocalDiscriminatorsPtr() itself, so the append and the following in-place rows_offset compaction could mutate cached storage. Now clones the discriminators via IColumn::mutate when shared, same move-based form. Adds 04504_variant_discriminators_cow_safe_rows_offset (reads a Variant and its subcolumns under PREWHERE on a wide part with index_granularity = 2, index_granularity_bytes = 0, driving rows_offset > 0 reads).

    Validated locally against a fresh ASan build: the new test and the sibling Variant tests (03725, 03925) match their references with no ASan report.

@clickhouse-gh

clickhouse-gh Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.60% 85.60% +0.00%
Functions 92.70% 92.70% +0.00%
Branches 77.80% 77.80% +0.00%

Changed lines: Changed C/C++ lines covered: 35/47 (74.47%) · Uncovered code

Full report · Diff report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

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 self-assigned this Jul 5, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 5, 2026
Merged via the queue into master with commit 5330b09 Jul 5, 2026
175 checks passed
@alexey-milovidov
alexey-milovidov deleted the cow-safe-merge-read-deserialize-double-free branch July 5, 2026 10:55
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 5, 2026

@Avogar Avogar 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.

I don't understand changes in serializations. It leads to extra data copy on shared subcolumns deserialization. And I don't see why we need to change this. It was intentional to share subcolumns and use assumeMutable() in serializations to insert into all shared instances of the same subcolumn. All MergeTree readers return constant ColumnPtr, so it should not lead to any problems if columns share the same subcolumns. We just can't use assumeMutable() outside of serializations (like in applyPatches).

@Avogar

Avogar commented Jul 14, 2026 •

Copy link
Copy Markdown
Member

And the test doesn't reproduce any problems in older binaries

@Avogar

Avogar commented Jul 14, 2026

Copy link
Copy Markdown
Member

I will revert this

Avogar added a commit that referenced this pull request Jul 16, 2026
…egression

PR #109105 replaced assumeMutable with IColumn::mutate in serialization code.
In ISerialization::deserializeBinaryBulkWithMultipleStreams this caused a severe
performance regression (3-4x slower) because columns are intentionally shared
via the substreams cache between multiple readers (e.g. reading both a full
Tuple column and its named subcolumns). IColumn::mutate clones the column when
use_count > 1, defeating the cache and causing unnecessary copies on every
readRows call.

MergeTree readers return a set of constant columns that are not mutated after
reading, so sharing subcolumns via the same ColumnPtr is safe and assumeMutable
is the correct approach in the base deserialization path.

Keep IColumn::mutate in the other four call sites where the column is not shared
via the cache:
- ISerialization::insertDataFromCachedColumn
- SerializationArrayOffsets (rows_offset > 0 path, cache stores cut() copy)
- SerializationStringSize (rows_offset > 0 path, cache stores cut() copy)
- SerializationVariant discriminators (rows_offset > 0 path, cache stores cut() copy)

Also adds a performance test for Tuple subcolumn deserialization covering both
wide parts (with alternating granule skipping via minmax index) and compact
parts (with nested Tuple to exercise substream cache sharing).

Co-Authored-By: Claude Opus 4.6 <[email protected]>
alexey-milovidov added a commit to groeneai/ClickHouse that referenced this pull request Jul 27, 2026
…ze states

The crash family tracked in issue ClickHouse#105626 (SEGV in
CompressedReadBufferFromFile::readBig during merges, ASan double-free on
reader stream buffers, heap-use-after-free on columns freed by
SubstreamsCacheColumnWithNumReadRowsElement destruction while still
referenced by MergeTreeRangeReader) is caused by broken copy-on-write
reference counting: some holder of a column obtains it without a counted
reference, so the column is freed while still in use. The IColumn::mutate
sweeps (ClickHouse#107451, ClickHouse#109105) did not stop the family because they defend
against in-place mutation of shared columns, not against an under-counted
reference.

This change adds debug/sanitizer-build diagnostics that turn the weekly
flaky crashes into deterministic failures at the point where the
inconsistency is still observable:

- ColumnsOwnershipValidator: enumerates the column references that provably
  exist (from substreams cache elements, deserialize states, and result
  columns with their subcolumn trees) and checks that use_count covers
  them. Runs at the end of MergeTreeReaderWide::readRows and per granule in
  MergeTreeReaderCompactSingleBuffer::readRows, right before the caches are
  dropped. Throws LOGICAL_ERROR, which aborts in debug and sanitizer builds.
- forEachColumn enumeration hooks on ISubstreamsCacheElement and
  DeserializeBinaryBulkState, implemented for all elements and states that
  hold columns (column-with-num-read-rows element, sparse offsets element,
  Object shared data paths-data element, String size stream and full-column
  states, Variant element and null-map states, Dynamic element, Object
  dynamic/shared-data paths, Map key-value, LowCardinality).
- chasserts of the column->size() >= num_read_rows invariant at substreams
  cache insert and lookup and in insertDataFromCachedColumn (its consumers
  do insertRangeFrom(*cached, size - num_read_rows, num_read_rows), which
  would silently underflow).

All checks compile to no-ops in release builds.

Related: ClickHouse#105626

Co-Authored-By: Claude Fable 5 <[email protected]>
scanhex12 pushed a commit to scanhex12/ClickHouse that referenced this pull request Jul 29, 2026
…ze states

The crash family tracked in issue ClickHouse#105626 (SEGV in
CompressedReadBufferFromFile::readBig during merges, ASan double-free on
reader stream buffers, heap-use-after-free on columns freed by
SubstreamsCacheColumnWithNumReadRowsElement destruction while still
referenced by MergeTreeRangeReader) is caused by broken copy-on-write
reference counting: some holder of a column obtains it without a counted
reference, so the column is freed while still in use. The IColumn::mutate
sweeps (ClickHouse#107451, ClickHouse#109105) did not stop the family because they defend
against in-place mutation of shared columns, not against an under-counted
reference.

This change adds debug/sanitizer-build diagnostics that turn the weekly
flaky crashes into deterministic failures at the point where the
inconsistency is still observable:

- ColumnsOwnershipValidator: enumerates the column references that provably
  exist (from substreams cache elements, deserialize states, and result
  columns with their subcolumn trees) and checks that use_count covers
  them. Runs at the end of MergeTreeReaderWide::readRows and per granule in
  MergeTreeReaderCompactSingleBuffer::readRows, right before the caches are
  dropped. Throws LOGICAL_ERROR, which aborts in debug and sanitizer builds.
- forEachColumn enumeration hooks on ISubstreamsCacheElement and
  DeserializeBinaryBulkState, implemented for all elements and states that
  hold columns (column-with-num-read-rows element, sparse offsets element,
  Object shared data paths-data element, String size stream and full-column
  states, Variant element and null-map states, Dynamic element, Object
  dynamic/shared-data paths, Map key-value, LowCardinality).
- chasserts of the column->size() >= num_read_rows invariant at substreams
  cache insert and lookup and in insertDataFromCachedColumn (its consumers
  do insertRangeFrom(*cached, size - num_read_rows, num_read_rows), which
  would silently underflow).

All checks compile to no-ops in release builds.

Related: ClickHouse#105626

Co-Authored-By: Claude Fable 5 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…ead-deserialize-double-free

Extend COW-safe `IColumn::mutate` sweep to deserialize and patch-apply paths
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-ci 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.

3 participants