Repository navigation
Fix heap-use-after-free in the EmbeddedRocksDB tuple key filter with a LowCardinality element - #125509
Conversation
…element `traverseDAGFilter` (multi-column overload, tuple-equality branch) bound a raw `const DataTypeTuple *` to the temporary returned by `removeNullable(recursiveRemoveLowCardinality(right->result_type))`. `recursiveRemoveLowCardinality` allocates a new `DataTypeNullable` / `DataTypeTuple` when a tuple element is `LowCardinality`, so that temporary was the only owner and was destroyed at the end of the declaration, while the per-element loop below kept reading `getElements()` from it. A scalar subquery such as `(SELECT (lc_col, id) FROM t LIMIT 1)` yields `Nullable(Tuple(LowCardinality(String), UInt64))`, which takes the allocating branch, so `WHERE (k, id) = (SELECT ...)` on an `EmbeddedRocksDB` table with a composite `PRIMARY KEY` read freed memory (ASan: heap-use-after-free). Introduced by ClickHouse#118689. Keep the stripped type in a named `DataTypePtr`, the shape the sibling call sites in the same file (single-column `equals`, tuple `IN`) already use. Closes ClickHouse#120527 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review (1 finding).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261012-210800 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261012-191400 |
|
Workflow [PR], commit [01e7e77] Summary: ✅
AI ReviewSummaryThis PR fixes a real lifetime bug in Final Verdict✅ No review findings. From a code-review perspective this looks ready; the remaining step is for the still-pending CI jobs to finish green. |
Backport #125509 to 26.9: Fix heap-use-after-free in the EmbeddedRocksDB tuple key filter with a LowCardinality element
…sDB tuple key filter with a LowCardinality element
Closes: #120527
Related: #118689
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a heap-use-after-free when an
EmbeddedRocksDBtable with a compositePRIMARY KEYwas filtered by a tuple equality whose tuple has aLowCardinalityelement, e.g.WHERE (k, id) = (SELECT (name, id) FROM t LIMIT 1). Closes #120527.Description
On 26.9 (every stable release since
v26.9.1.1629-stable),WHERE (k, id) = (SELECT (name, id) FROM dim LIMIT 1)on anEmbeddedRocksDBtable withPRIMARY KEY (k, id), wherenameisLowCardinality(String), reads a freedDataTypeTuplewhile building the key filter (heap-use-after-free; an ASan build aborts).Root cause: the tuple-equality branch of
traverseDAGFilter(added in #118689) took.get()of the temporary returned byremoveNullable(recursiveRemoveLowCardinality(right->result_type)).recursiveRemoveLowCardinalityallocates a new type when a tuple element isLowCardinality, so that temporary was the only owner and died at the end of the declaration, while the per-element loop kept reading its element types. The scalar subquery yieldsNullable(Tuple(LowCardinality(String), UInt64)), which takes that allocating branch.Change: keep the stripped type in a named
DataTypePtr, the shape the single-columnequalsand tupleINbranches of the same file already use. OnlyEmbeddedRocksDBreaches the multi-column overload;RedisandKeeperMapuse the single-column one, which was already safe.Validation: found by automated review (the issue), no CI job has hit it. The new test aborts with heap-use-after-free on an ASan build of the base commit and passes on the fixed build. It passes 50/50 randomized runs, and the existing RocksDB / KeeperMap / KV key-filter tests pass.
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/125509]
Version info
26.10.1.2307-master(included in26.10and later)