Repository navigation
Fix UBSan in MergeTreeDataPartWriterCompact::cancel - #101292
Conversation
`streams_by_codec` can contain null entries when `addStreams` partially fails: `std::map::operator[]` value-initializes (inserts null) before `std::make_shared<CompressedStream>` runs, and if the allocation throws, the null entry persists. When `cancel` is later called (e.g. from the background executor's catch block), iterating and dereferencing these null entries is undefined behavior caught by UBSan. Add a null guard, consistent with the base class `MergeTreeDataPartWriterOnDisk::cancel` which already guards its optional stream pointers. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Workflow [PR], commit [d09cf92] Summary: ✅ AI ReviewSummaryThis PR fixes the Missing context
ClickHouse Rules
Final Verdict
|
|
Let's create a test using failpoints. |
|
FYI, this is the top reason for crashes of 26.3. |
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…ll check Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
After rewriting the code in an exception-safe way, we can no longer add a specific test. |
|
The |
|
The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix. |
…cellation The Wide writer's `addStreams` used `operator[]=make_unique<>()` which modifies the map before evaluating `make_unique`. If the constructor throws (e.g. `MEMORY_LIMIT_EXCEEDED`), a null entry remains in `column_streams`. When `cancel()` iterates the map and dereferences the null entry, it crashes with SIGSEGV. Replace with `emplace` so `make_unique` is evaluated before the map is modified — if it throws, no null entry is left. Also add a defensive null check in `cancel()`. Same class of bug as #101292 (Compact writer fix). ClickHouse/clickhouse-private#1518 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
When the join optimizer reorders a multi-table join, type changes (e.g., `toNullable` from a LEFT JOIN) were applied at the first step involving the affected relation, regardless of whether the join that causes the type change was actually being executed at that step. For example, with `t1 LEFT JOIN t2 INNER JOIN t3`, if the optimizer reorders to join t2-t3 first, the Nullable wrapping for t2 (from the LEFT JOIN with t1) was incorrectly applied at the t2-t3 step. This replaced original input nodes in `current_input_nodes`, so when the t1-t2 LEFT JOIN expression was later processed, it could not find the original `t2.id` INPUT node — causing the exception "Cannot fold actions for projection". The fix checks the `join_kinds` dependency before applying type changes: a type change for a relation is only applied when the other side of the type-changing join is also present in the current step's joined set. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=101292&sha=2d129c6df44b0ed28a05397e55abe0cbbff9bb1e&name_0=PR&name_1=Stress%20test%20%28arm_msan%29 #101292 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…riter-cancel # Conflicts: # src/Common/FailPoint.cpp
LLVM Coverage Report
Changed lines: 100.00% (15/15) · Uncovered code |
Cherry pick #101292 to 26.4: Fix UBSan in MergeTreeDataPartWriterCompact::cancel
Backport #101292 to 26.4: Fix UBSan in MergeTreeDataPartWriterCompact::cancel
Cherry pick #101292 to 26.3: Fix UBSan in MergeTreeDataPartWriterCompact::cancel
Backport #101292 to 26.3: Fix UBSan in MergeTreeDataPartWriterCompact::cancel
…terCompact::cancel
…1292 Backport ClickHouse#101292 to 26.4: Fix UBSan in MergeTreeDataPartWriterCompact::cancel
STOR: compact-part writer cancelled after a failed stream allocation -> crash (UB). Effect in the production build a394e92: its upstream test(s) 04113_compact_part_writer_cancel_on_exception fail on it and pass on official 26.8.8.8, run on isolated servers (evidence/fix_ci_20260925/upstream_repro/server_triage_PROD263_vs_UP2688.tsv). Upstream patch unchanged, with its test(s): 04113_compact_part_writer_cancel_on_exception. Co-Authored-By: Claude Opus 5.5 <[email protected]>
In
MergeTreeDataPartWriterCompact::addStreams,streams_by_codec[codec_id]inserts a nullshared_ptrviaoperator[]beforestd::make_sharedruns. If the allocation throws, the null entry remains in the map. Whencancelis later called (e.g. from the background executor's error path), it iteratesstreams_by_codecand dereferences the null entry, causing UBSan to report undefined behavior.The fix rewrites the insertion to be exception-safe: use
findto check for an existing entry, and onlyemplacethe fully-constructedshared_ptrreturned bystd::make_shared. If the allocation throws, the map is not modified, so no null entries can be observed bycancel.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix undefined behavior in
MergeTreeDataPartWriterCompact::cancelwhen a stream allocation fails.Documentation entry for user-facing changes
Version info
26.5.1.16426.4.2.6,26.3.13.10