Repository navigation
Fix use-after-free on renaming Delta Lake columns to their physical names - #131029
Conversation
…ames `DeltaLakeMetadataDeltaKernel::prepareReadingFromFormat` renamed the requested columns to their physical names in place, while iterating over the same `ColumnsDescription`. Under column mapping the physical name of a column can be the logical name of another one: after `k` is renamed to `k_old` and `v` to `k`, `k_old` is stored as `k`. When `k_old` comes first, `ColumnsDescription::rename` to the existing `k` makes `modify_key` erase `k_old`, and the loop reads the freed node. Build a new description with the physical names instead. Found by the AST fuzzer in the stress test of #120906: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120906&sha=4b935993be52f957f83759b7ea8fa1a133ae82c5&name_0=PR&name_1=Stress%20test%20%28arm_asan_ubsan%29 Caused by: #130793 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [343f308] Summary: ✅
AI ReviewSummaryThe PR fixes a use-after-free when Delta Lake column mapping causes physical names to overlap logical names, and reapplies the related Top-K correctness fix. At head Missing context / blind spots
Findings
Tests
Final VerdictStatus: |
…e case Pass `HTTPConnectionGroupType::STORAGE` to `createClientConfiguration`, the same as the master fix. Remove the `WHERE` query from the test: with filter push down it depends on the separate filter-mapping bug. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Followup for the skill: #131044 |
…th column mapping" This reverts commit 3e30e2e.
The `AmberMap` sync #129464 is reverted in #131043, so `createClientConfiguration` takes `bool for_disk_s3` again. Related: #131043 Co-Authored-By: Claude Opus 5.5 <[email protected]>
| NamesAndTypesList requested_virtual_columns; | ||
| /// Columns of `source_header` that the format reads under other names (the physical names of a Delta | ||
| /// Lake table with column mapping). `format_header` can have another column under such a name. | ||
| NameSet columns_read_under_other_names; |
There was a problem hiding this comment.
The new guard depends on this set, but ReadFromFormatInfo::serialize and ReadFromFormatInfo::deserialize in prepareReadingFromFormat.cpp:444–503 omit it: a round trip preserves the logical source_header and physical format_header while leaving columns_read_under_other_names empty. With this test's mapping (k_old → k, k → v), supportsTopKDynamicFilter then accepts logical k against the unrelated physical k again.
Skipping Top-K on the distributing initiator does not establish safety after deserialization: doExecuteTask builds the worker pipeline with optimization enabled, and distributed sorting retains a local LimitStep over a full SortingStep. The Cloud-only read-step deserializer is absent from this checkout, so please verify whether it reconstructs this exclusion before optimization. Otherwise preserve/reconstruct the set across the read-info round trip and add a focused serialized-plan regression; the new local-read tests do not exercise this boundary.
There was a problem hiding this comment.
@groeneai, there was an outage, so this may have been missed: please make a follow-up PR for this (see #131029 (comment)).
There was a problem hiding this comment.
Acknowledged. I'm investigating preserving columns_read_under_other_names across the ReadFromFormatInfo serialize/deserialize round trip; I'll follow up here with a PR (or my findings) shortly.
There was a problem hiding this comment.
Follow-up PR: #131173
It writes the set as an optional trailer of ReadFromFormatInfo::serialize (only when it is not empty, so every other read keeps its bytes) and reads it back in deserialize. The only callers are the CLICKHOUSE_CLOUD ReadFromObjectStorageStep serializers, so no SQL test reaches it; the regression is a gtest of the round trip that fails on master.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units7 translation units recompiled, 13 s compile time in total, 7 of them have a recent master baseline. |
Cherry pick #131029 to 26.3: Fix use-after-free on renaming Delta Lake columns to their physical names
Resolve the conflicts of the backport of #131029 to 26.3: - `DeltaLakeMetadataDeltaKernel::prepareReadingFromFormat`: keep the fix (build a new `ColumnsDescription` instead of renaming in place), using the 26.3 `DeltaLake::getPhysicalName`. - 26.3 has no top-K dynamic filtering, so drop the `supportsTopKDynamicFilter` guard, the `columns_read_under_other_names` field that only it used, and the test `05620_delta_lake_top_k_dynamic_filtering_column_mapping`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…olumns to their physical names
Resolve conflicts for the 26.9 backport of #131029: - 26.9 has no `ReadFromObjectStorageStep::supportsTopKDynamicFilter` (top-K dynamic filtering is not applied to object storage reads there), so the `columns_read_under_other_names` guard, its plumbing in `ReadFromFormatInfo`, and the test `05620_delta_lake_top_k_dynamic_filtering_column_mapping` are dropped. - The use-after-free fix in `DeltaLakeMetadataDeltaKernel::prepareReadingFromFormat` is kept, adapted to the 26.9 `DeltaLake::getPhysicalName` helper, with the test `05621_delta_lake_column_mapping_swapped_names_order`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry pick #131029 to 26.8: Fix use-after-free on renaming Delta Lake columns to their physical names
…olumns to their physical names
Cherry pick #131029 to 26.9: Fix use-after-free on renaming Delta Lake columns to their physical names
…olumns to their physical names
Cherry pick #131029 to 26.10: Fix use-after-free on renaming Delta Lake columns to their physical names
…columns to their physical names
Backport #131029 to 26.10: Fix use-after-free on renaming Delta Lake columns to their physical names
The backport commit `bfc5837e5dcc` was created on top of `857eb0600f48` but its tree is that of `24d9096599b8` (a release-line commit not present in the current `26.9`) plus the 3-file fix from #131029. A normal merge would therefore drag ~785 unrelated files into the PR and conflict. Resolve by taking the current `origin/26.9` tree and applying only the intended change (`24d9096599b8..bfc5837`), so the PR diff against `26.9` is exactly the fix: `DeltaLakeMetadataDeltaKernel.cpp` and test `05621_delta_lake_column_mapping_swapped_names_order`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Backport #131029 to 26.3: Fix use-after-free on renaming Delta Lake columns to their physical names
Backport #131029 to 26.9: Fix use-after-free on renaming Delta Lake columns to their physical names
Backport #131029 to 26.8: Fix use-after-free on renaming Delta Lake columns to their physical names
Related: #86477
Related: #130793
Related: #120906
Related: #131045
This PR also reapplies #130793, which was reverted in #131045, so it contains both the original change and the fix.
DeltaLakeMetadataDeltaKernel::prepareReadingFromFormatrenamed the requested columns to their physical names in place, while iterating over the sameColumnsDescription. Under column mapping, the physical name of a column can be the logical name of another one: afterkis renamed tok_oldandvtok,k_oldis stored ask. Whenk_oldis requested beforek(SELECT k_old, k ...),ColumnsDescription::renameto the still existingkmakesmodify_keyerasek_old, and the loop reads the freed node (heap-use-after-free under ASan, a silently lost column otherwise). The fix builds a new description with the physical names instead.The in-place rename was added in #86477 and is in every release since 25.9. #130793 did not change it: its test has such a table, and the AST fuzzer reordered the columns of its query, in the stress test of #120906: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120906&sha=4b935993be52f957f83759b7ea8fa1a133ae82c5&name_0=PR&name_1=Stress%20test%20%28arm_asan_ubsan%29
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a use-after-free on reading a Delta Lake table with column mapping in which a column is stored under the name of another column (for example, after column mapping is enabled on an existing table and columns are renamed), when the columns are requested in a particular order, such as
SELECT k_old, k.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/131029]
Version info
26.11.1.2128-master(included in26.11and later)26.10.5.6,26.9.30.6,26.8.39.8,26.3.65.9