Repository navigation
Fix dangling NameSet reference in UserDefinedSQLFunctionVisitor - #106121
Conversation
`UserDefinedSQLFunctionVisitor::tryToReplaceFunction` constructed a
`QueryNormalizer::Data` with a `{}` temporary as the `source_columns_set`
argument. Because `Data` stores `source_columns_set` as a `const NameSet &`,
the temporary's lifetime ended as soon as the constructor returned, leaving
the reference member dangling. The subsequent `QueryNormalizer::visit` on
the UDF body could then read that destroyed `unordered_set` from
`QueryNormalizer::visit(ASTIdentifier &, ...)` when
`prefer_column_name_to_alias` is set, which the MSan build catches as
use-of-uninitialized-value with a "Member fields were destroyed" stack
pointing at the same statement.
Trigger conditions: `skip_redundant_aliases_in_udf = 1` (gates the path)
and `prefer_column_name_to_alias = 1` (gates the read of `source_columns_set`).
Reproduced with the provided MSan binary against a UDF-using
`SELECT ... SETTINGS enable_analyzer = 0` and against a `CREATE TABLE` with
the UDF in a `MATERIALIZED` expression. Both stacks match the BuzzHouse
report at:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=549ac9afd4ee4fd58d177ad5b7b88b4a517805d6&name_0=MasterCI&name_1=BuzzHouse+%28amd_msan%29
Fix: give the empty `NameSet` a named local so it lives for the whole
statement.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Workflow [PR], commit [0219d84] Summary: ⏳
AI ReviewSummaryThis PR fixes the dangling Final VerdictStatus: ✅ Approve |
`QueryNormalizer::Data` stores `source_columns_set` by reference, so any
caller passing `{}` for that argument leaves the member dangling. Beyond
the UDF visitor fixed in the previous commit, two other call sites had
the same pattern:
* `StorageWindowView::getInnerTableCreateQuery` — production code path
used when creating the inner table of a window view; would also be
affected on the `prefer_column_name_to_alias = 1` path.
* `gtest_cycle_aliases` — both `SimpleLoopAlias` and `SimpleCycleAlias`
test cases; benign in practice because the default `Settings` keeps
`prefer_column_name_to_alias = 0`, but still UB.
Apply the same named-local fix in all three.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The flaky check runs the test in concurrent iterations. Because SQL user-defined functions are global server objects (not per-database), the fixed `udf_normalizer_04280` name collided across concurrent runs, failing the `CREATE FUNCTION` with `FUNCTION_ALREADY_EXISTS` (error 609). This matches the convention used by the rest of the UDF test suite (e.g. `02354_vector_search_reference_vector_types`, `01856_create_function`), which tag such tests `no-parallel` for the same reason. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106121&sha=e219665bcc03bb1d7f3fcdfb06b3cd3630aabe2f&name_0=PR Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
The "Server died" / "Unknown error" failure in Stateless tests (amd_asan_ubsan, db disk, distributed plan, sequential) is unrelated to this PR — it is the known flaky crash tracked in #105626 ( All remaining failures were iterations of the new |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 20/20 (100.00%) | Lost baseline coverage: none · Uncovered code |
UserDefinedSQLFunctionVisitor::tryToReplaceFunctionconstructed aQueryNormalizer::Datawith a{}temporary as thesource_columns_setargument. BecauseDatastoressource_columns_setas aconst NameSet &, the temporary's lifetime ended as soon as the constructor returned, leaving the reference member dangling. The subsequentQueryNormalizer::visiton the UDF body could then read that destroyedunordered_setfromQueryNormalizer::visit(ASTIdentifier &, ...)whenprefer_column_name_to_aliasis set, which the MSan build catches as use-of-uninitialized-value with a "Member fields were destroyed" stack pointing at the same statement.Trigger conditions:
skip_redundant_aliases_in_udf = 1(gates the path) andprefer_column_name_to_alias = 1(gates the read ofsource_columns_set).Reproduced with the provided MSan binary against a UDF-using
SELECT ... SETTINGS enable_analyzer = 0and against aCREATE TABLEwith the UDF in aMATERIALIZEDexpression. Both stacks match the BuzzHouse report at:https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=549ac9afd4ee4fd58d177ad5b7b88b4a517805d6&name_0=MasterCI&name_1=BuzzHouse+%28amd_msan%29
Fix: give the empty
NameSeta named local so it lives for the whole statement.Closes #106040
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixes possible memory corruption when expanding SQL user-defined functions with
prefer_column_name_to_alias enabled.Version info
26.6.1.294