Repository navigation
Fix UBSan null deref in StorageTimeSeries constructor - #104905
Conversation
When a `TimeSeries` table is constructed with an external (non-inner) metrics table, the constructor calls `tryGetTable` to check the target table's columns for `LowCardinality`. During `ATTACH` (server startup), the target table may not yet be loaded, so `tryGetTable` returns `nullptr`. The code then unconditionally dereferences it to call `getInMemoryMetadataPtr`, triggering a UBSan "member call on null pointer" error. The bug surfaces in stress tests that build with UBSan and abort on logical error: e.g. https://s3.amazonaws.com/clickhouse-test-reports/PRs/97254/44e317738d517ea52e1fbf4bb87a75c512c8f60a/stress_test_amd_asan_ubsan/clickhouse-server.log.zst ``` src/Storages/StorageTimeSeries.cpp:171:36: runtime error: member call on null pointer of type 'DB::IStorage' SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /ClickHouse/src/Storages/StorageTimeSeries.cpp:171:36 ``` Caused by commit 16e69df ("make `getInMemoryMetadataPtr` aware of context"), which rewrote `table->getInMemoryMetadataPtr()` to `table->getInMemoryMetadataPtr(getContext(), false)` without adding the missing null check. Fix: only perform the `LowCardinality` validation when `tryGetTable` returns a non-null pointer. If the target table can't be resolved right now (typically because we are attaching tables at startup), the check is skipped — the next time the table is created the validator will catch any unsupported columns. Surfaced in CI for #97254 but unrelated to that PR. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Workflow [PR], commit [59dbf62] Summary: ✅ AI ReviewSummaryThis PR fixes a null dereference in Final VerdictStatus: ✅ Approve |
The `LowCardinality` check on the external `METRICS` target now runs only when `mode < LoadingStrictnessLevel::ATTACH`, matching the gating used by `validator.validateColumns` immediately above. This removes the attach-order-dependent behaviour the bot reviewer flagged: at server startup the target table may or may not be loaded yet, and we should not re-validate something that was already validated at CREATE time. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
At CREATE time `initTarget` has already resolved the external metrics target via `DatabaseCatalog::getTable`, which throws if the table is missing. Using `tryGetTable` here for the `LowCardinality` validation created a fail-open path: if lookup unexpectedly returned `nullptr`, the validation was silently skipped and an unsupported schema could be accepted. Switch back to `getTable` to keep the validation contract deterministic and consistent with the project's fail-close policy. The original UBSan null-deref scenario only happens during `ATTACH`, which is already gated by `mode < LoadingStrictnessLevel::ATTACH`.
|
The CI failures on this PR are unrelated to the
@groeneai, please investigate the |
Ergus
left a comment
There was a problem hiding this comment.
LGTM. However I think that this should be considered a "Bug Fix" not a "CI Fix or Improvement"
|
Follow-up: the latest CI run also surfaced two failures not in my previous comment, both confirmed unrelated to
|
The previous commits gate the `StorageTimeSeries` constructor's external metrics validation behind `mode < LoadingStrictnessLevel::ATTACH`, mirroring the existing `validateColumns` gating. Without the fix, attaching a `TimeSeries` table whose external metrics target was not yet loaded would dereference a null pointer returned by `tryGetTable` and crash. The new test reproduces the ordering by detaching both tables and then re-attaching the `TimeSeries` table before its external metrics target. Verified locally: with the previous (buggy) binary the `ATTACH` call hits a `SIGSEGV` in `StorageTimeSeries::StorageTimeSeries`; with the fix the test passes. Addresses review feedback on #104905. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…ated` The experimental `TimeSeries` table engine does not round-trip through `DatabaseReplicated`: `DETACH`/`ATTACH` of the metrics target hangs the test cleanup, which then hung the entire CI run (719s timeout for this test, then 114 cascading HTTP timeouts). Add `Tags: no-replicated-database`, mirroring the other `TimeSeries` tests (`04131_prometheus_query_parser`, `04202_prometheus_query_datetime64_nanosecond_modern_timestamp`). CI report: #104905 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Pushed two updates:
Remaining red checks look unrelated to this PR:
@groeneai, could you investigate the |
`LowCardnality` -> `LowCardinality` so diagnostics stay searchable and consistent with the type name. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Merged One newly observed unrelated failure on the previous CI run:
@groeneai, please track |
|
Confirmed via CIDB — tracking The failing test ( instance.wait_for_log_line(f"{kafka_table}.*Committed offset 128")
assert TSV(instance.query(f"SELECT count() FROM test.{kafka_table}_data")) == TSV("640")
assert TSV(instance.query(f"SELECT count() FROM test.{kafka_table}_errors")) == TSV("64")The Kafka offset commit and the materialized view's
This is the same family I'm already tracking as a chronic flake — Fix plan (separate PR): replace the bare assert with No open |
…formed_json
Both tests in test_storage_kafka/test_batch_fast.py wait for the
Kafka 'Committed offset 128' log line and then assert the destination
row counts immediately:
instance.wait_for_log_line(f'{kafka_table}.*Committed offset 128')
assert TSV(instance.query(f'SELECT count() FROM test.{kafka_table}_data'))
== TSV('...')
assert TSV(instance.query(f'SELECT count() FROM test.{kafka_table}_errors'))
== TSV('64')
The offset commit and the materialized-view INSERT into the destination
MergeTree are not strictly ordered: the consumer side can log
'Committed offset 128' before the last MV block has finished flushing,
so the immediate SELECT undercounts (typically by exactly the last
block, i.e. assert 54 == 64).
Across both parametrized variants of each test the family has hit 23+
failures across 5 distinct unrelated PRs in the last 30 days (e.g.
ClickHouse#96886, ClickHouse#104902, ClickHouse#104905), with 0 master failures. Surfaced again by
@alexey-milovidov on
ClickHouse#104905 (comment).
The helper file in the same suite already acknowledges this anti-pattern
(tests/integration/helpers/kafka/common.py:463):
"Since everything is async and shaky when receiving messages from
Kafka, we may want to try and check results multiple times in a loop."
Most other tests in test_batch_fast.py already use query_with_retry
with a check_callback for exactly this reason (see e.g. line 1053,
1516). These two tests were the outliers.
Replace the bare assert with query_with_retry + check_callback. The
asserted values are unchanged, so no test intent is weakened: if the
count never reaches the expected value, query_with_retry returns the
last observed result and the surrounding assert ... == EXPECTED fails
loudly.
azat
left a comment
There was a problem hiding this comment.
Did not notice this and come up with the same fix more or less
LLVM Coverage Report
Changed lines: 88.89% (8/9) · Uncovered code |
…-series-null-deref Fix UBSan null deref in StorageTimeSeries constructor
When a
TimeSeriestable is constructed with an external (non-inner) metrics table, the constructor callstryGetTableto check the target table's columns forLowCardinality. DuringATTACH(server startup), the target table may not yet be loaded, sotryGetTablereturnsnullptr. The code then unconditionally dereferences it to callgetInMemoryMetadataPtr, triggering a UBSan "member call on null pointer" error and aborting the server (withabort_on_logical_error.yamlenabled in stress tests).Symptom in CI:
Reproduction surface: https://s3.amazonaws.com/clickhouse-test-reports/PRs/97254/44e317738d517ea52e1fbf4bb87a75c512c8f60a/stress_test_amd_asan_ubsan/clickhouse-server.log.zst (surfaced as "Cannot start clickhouse-server" in the Stress test (amd_asan_ubsan) report for #97254 - the failure itself is unrelated to that PR).
Root cause: commit 16e69df ("make
getInMemoryMetadataPtraware of context") rewrotetable->getInMemoryMetadataPtr()totable->getInMemoryMetadataPtr(getContext(), false)but kept the implicit assumption thattryGetTablealways returns non-null.Fix: only perform the
LowCardinalityvalidation whentryGetTablereturns a non-null pointer. If the target table can't be resolved right now (typically because we are attaching tables at startup), the check is skipped - the next time the table is created the validator will catch any unsupported columns.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix UBSan null pointer dereference in
StorageTimeSeriesconstructor when the external metrics target table is not yet loaded.Documentation entry for user-facing changes
No documentation needed - internal fix to silence a UBSan error that aborted the server during stress tests on ASan+UBSan builds.
Version info
26.5.1.869