Repository navigation
Erase sorted_dynamic_paths entries before dynamic_paths ones - #100758
Conversation
|
Workflow [PR], commit [5e92a4e] Summary: ✅ AI ReviewSummaryThis PR fixes rollback correctness in ClickHouse Rules
Final Verdict
|
|
Can we add a test somehow? At least a new unit test in |
There was a problem hiding this comment.
Pull request overview
Fixes a potential use-after-free in ColumnObject::tryInsert rollback by ensuring sorted_dynamic_paths (a std::set<std::string_view>) does not retain views into erased dynamic_paths keys.
Changes:
- Update
ColumnObject::tryInsertrollback to erase entries fromsorted_dynamic_pathsbefore erasing fromdynamic_paths.
|
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. |
Avogar
left a comment
There was a problem hiding this comment.
Let's write a Changelog entry and fix comments in the test as bot suggested
|
The MSan stress test failure (MemorySanitizer: use-of-uninitialized-value, STID 4179-5154 or 4148-3044) is a known pre-existing issue unrelated to this PR. Fix: #102158 |
|
Hi — this PR may need backporting to Affected code: Why: The bug exists in If this should be backported, consider adding |
Cherry pick #100758 to 25.8: Erase sorted_dynamic_paths entries before dynamic_paths ones
Cherry pick #100758 to 26.2: Erase sorted_dynamic_paths entries before dynamic_paths ones
Cherry pick #100758 to 26.3: Erase sorted_dynamic_paths entries before dynamic_paths ones
Cherry pick #100758 to 26.4: Erase sorted_dynamic_paths entries before dynamic_paths ones
Backport #100758 to 26.4: Erase sorted_dynamic_paths entries before dynamic_paths ones
Backport #100758 to 26.3: Erase sorted_dynamic_paths entries before dynamic_paths ones
Backport #100758 to 26.2: Erase sorted_dynamic_paths entries before dynamic_paths ones
Backport #100758 to 25.8: Erase sorted_dynamic_paths entries before dynamic_paths ones
…s before dynamic_paths ones
…0758 Backport ClickHouse#100758 to 26.4: Erase sorted_dynamic_paths entries before dynamic_paths ones
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix an exception that could occur when inserting a row into a JSON column where the row introduced a new dynamic field alongside a typed field with an incompatible value, and the column was subsequently used as a GROUP BY key.
Documentation entry for user-facing changes
Attempt to fix incident 1512.
/fix https://github.com/ClickHouse/clickhouse-core-incidents/issues/1512
ColumnObject::tryInsertcontains arestore_sizesrollback lambda that removes newly-added dynamic paths when the insert fails mid-object. It correctly erases each path fromdynamic_pathsanddynamic_paths_ptrs, but not erase it fromsorted_dynamic_pathsfirst.sorted_dynamic_pathsis anstd::set<std::string_view>whose string_views point into thestd::stringkeys owned bydynamic_paths.After
dynamic_paths.erase(path)frees the key string, the corresponding view in sorted_dynamic_paths becomes dangling.The bug only fires when all of the following are true:
tryInsertis called on a ColumnObject with an object that contains a path not yet in the column (triggeringtryToAddNewDynamicPath).ColumnObjectis later serialised viaserializeValueIntoArena(GROUP BY keys) or has another dynamic path added (triggering set comparison).The crash manifests as a segfault deep inside
SerializationObject::serializeBinaryBulkStatePrefixwhen iterating or calling .size() ondynamic_paths, making the root cause non-obvious without ASAN.Version info
26.5.1.18526.4.1.1138,26.3.11.12,26.2.19.16,25.8.24.21