Skip to content

Initialize uninitialized class members flagged by SVACE static analysis - #106154

Closed
groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-105843-svace-uninit-members
Closed

groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-105843-svace-uninit-members

Conversation

@groeneai

Copy link
Copy Markdown
Collaborator

SVACE static analysis flagged two primitive class members without in-class initializers, both reachable before any later assignment.

IMergeTreeDataPart::metadata_version is read via getMetadataVersion and normally set later in setColumns, so any access between construction and setColumns reads indeterminate memory.

ServersHashRing::nodes_num is read via size and only assigned at the end of a non-empty rebuild. The empty-set early-return branch leaves it unchanged, so size returns a garbage or stale value after rebuild with an empty set.

The patch adds = 0 initializers in both declarations and resets nodes_num before the early-return in rebuild to match the semantics of the cleared ring. Matches the suggestion in #105843 exactly.

Closes #105843.

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

N/A (SVACE hygiene fix; no user-visible behavior change).

Documentation entry for user-facing changes

  • Documentation is unaffected.

`IMergeTreeDataPart::metadata_version` was declared without an in-class
initializer, so reading it via `getMetadataVersion` before `setColumns`
returned an indeterminate value (UB).

`ServersHashRing::nodes_num` was also declared without an initializer
and not reset in the empty-set early-return branch of `rebuild`, so
calling `size` before the first non-empty rebuild or after an empty
rebuild returned a garbage or stale value.

Both findings come from Issue ClickHouse#105843 (Linux Verification Center, SVACE
static analysis); the patch matches the suggested fix exactly.

Closes ClickHouse#105843
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

This is an SVACE-driven hygiene fix, not a CI failure reproduction. Some items are N/A.

# Question Answer
a Deterministic repro? N/A. The bug is theoretical; no runtime crash is reachable in current code. SVACE static analysis flagged the missing initializers in #105843.
b Root cause explained? Yes. IMergeTreeDataPart::metadata_version is read via getMetadataVersion and only assigned later in setColumns — between construction and that point the field holds indeterminate memory. ServersHashRing::nodes_num is read via size and only assigned at the end of a non-empty rebuild; the empty-set early-return leaves it unchanged, so size returns garbage on the first call or stale on subsequent empty rebuilds.
c Fix matches root cause? Yes. Adds in-class = 0 initializers on both members, plus resets nodes_num = 0 in rebuild before the empty-set early-return — exactly the suggestion from the issue.
d Test intent preserved? N/A. No tests modified. Behavior change is strictly safer: previously-indeterminate reads now return 0.
e Both directions demonstrated? Partial. The "without fix" direction is not currently observable at runtime (existing call sites set metadata_version via loadColumns/setColumns before any read; size on ServersHashRing is not currently called externally — only chooseServer and rebuild). The "with fix" direction is verified by inspection: trivial primitive initializers, no codegen risk.
f Fix is general, not narrow? Yes. In-class initializers cover every constructor (current and future). Resetting nodes_num in rebuild covers both the first-call-with-empty path and the subsequent-empty-rebuild stale-value path. We did not widen the scope to other primitive members not flagged by SVACE.

session: cron:clickhouse-ci-task-worker:20260530-114500

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @alesapin @kssenii — trivial 3-line defense-in-depth fix for SVACE UNINIT.CTOR findings in #105843 (metadata_version in IMergeTreeDataPart.h and nodes_num in ServersHashRing). Could you take a look?

@clickhouse-gh

clickhouse-gh Bot commented May 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [58adf8a]

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label May 30, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 30, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.40% 84.40% +0.00%
Functions 91.40% 91.40% +0.00%
Branches 76.90% 76.90% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 4/4 (100.00%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 1 line(s) · Uncovered code

Full report · Diff report

@alexey-milovidov

Copy link
Copy Markdown
Member

@groeneai, first we have to fix the problem "Server died" found by our CI. Please send a fix in a separate PR.
Only after resolving real problems like that one, we can continue on this PR.

@alexey-milovidov alexey-milovidov self-assigned this May 31, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

This PR implements a tiny part of #100399

@groeneai

Copy link
Copy Markdown
Collaborator Author

@alexey-milovidov investigated the 'Server died' on Stateless tests (arm_asan_ubsan, targeted) (commit cb7df05). Findings:

  • All 1683 tests passed (Failed: 0, Passed: 1683, Skipped: 62).
  • Server exited normally: Application: Child process exited normally with code 0 at 17:16:24. No SIGSEGV / SIGABRT / sanitizer report / Logical error / BaseDaemon signal entry anywhere in the log.
  • Server.err.log contains 1902 errors, all TOO_MANY_PARTS / SOCKET_TIMEOUT / NETWORK_ERROR from BgDistSchPool trying to ship system tables (text_log, processors_profile_log, etc.) to the CIDB staging cluster kng4alm55c.us-east-2.aws.clickhouse-staging.com:9440. Sample error: Too many parts (3071 with average size of 948.28 MiB) in table 'default.processors_profile_log_*'. Merges are processing significantly slower than inserts.
  • The runner's check_ci 'Server died' verdict appears triggered by the volume of stderr spam, not by an actual server crash.

This matches the chronic CI infrastructure pattern. CIDB 30-day: 77 'Server died' hits on this check name across 57 distinct PRs, 0 master hits. 2026-05-30 alone: 50 hits across 43 unrelated PRs — #106154 is one of 43 victims of the same staging-cluster overload window (other examples include #80263, #101796, #103706, #105019, #105375 — all unrelated codepaths).

PR #106154's actual change is 3 lines (= 0 initializers in two header members + reset before empty-set early return) and cannot cause TOO_MANY_PARTS at a remote staging cluster.

Per the project rule about not making speculative code changes for failures that can't be backed by a reproducer or report (per Algunenano on #105675), I'm not filing a separate code-fix PR here. The actionable fix sits outside the ClickHouse repo (CIDB staging cluster merge throughput / runner stderr-volume heuristic).

Request: retrigger CI on #106154, or rebase to a post-recovery commit. Happy to dig deeper if you have a specific hypothesis — coredump, repro path, or a code region you suspect.

@alexey-milovidov

Copy link
Copy Markdown
Member

to the CIDB staging cluster kng4alm55c.us-east-2.aws.clickhouse-staging.com:9440

This might be a wrongly configured cluster or just bad infrastructure. Send another PR that will work around that by not making the CI check red if that staging cluster is not responding.

@groeneai

Copy link
Copy Markdown
Collaborator Author

@alexey-milovidov filed: #106176 — FTResultsProcessor now downgrades the synthetic Server died FAIL to an informational CIDB log cluster unresponsive SKIPPED when clickhouse-server.err.log is dominated by Distributed-shipping retries to the staging cluster and shows no real-crash markers (<Fatal>, sanitizer report, LOGICAL_ERROR, individual test failure). Any real crash keeps the legacy Server died path.

The classifier requires ≥100 <Error> lines and ≥95% Distributed-shipping-logger dominance — conservative enough that transient blips don't silence real failures. Logger-name match (DistributedAsyncInsertQueue / BgDistSchPool / system.<table>_sender) instead of the staging hostname, so a future host rename does not bypass the heuristic.

@alexey-milovidov

Copy link
Copy Markdown
Member

Ok. Now it is totally redundant, and it shows that SVACE adds nothing compared to clang-tidy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SAST] Uninitialized class members may cause undefined behavior in IMergeTreeDataPart and ServersHashRing

3 participants