Skip to content

Fix undefined behavior from reading uninitialized resolved_snapshot_id in ManifestFileIterator - #99038

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
zlareb1:fix/iceberg-null-snapshot-id-ub
Mar 16, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
zlareb1:fix/iceberg-null-snapshot-id-ub

Conversation

@zlareb1

@zlareb1 zlareb1 commented Mar 9, 2026 •

Copy link
Copy Markdown
Member

In ManifestFileIterator::processRow, resolved_snapshot_id is declared as an uninitialized Int64. In the else if branch reached when parsed_snapshot_id is null and the entry status is EXISTING, the uninitialized variable was passed to fmt::format — undefined behavior. The error message was also misleading: it said "has entry with snapshot_id '{}'" but this branch is entered precisely because there is no snapshot_id.

Fix: Remove resolved_snapshot_id from the format call and hardcode 'null' in the message, keeping the same style as the existing error message in the same function:
"Cannot read Iceberg table: manifest file '{}' has entry with snapshot_id 'null' for which write file schema is unknown"

Found via code review on PR #98231.

Changelog category (leave one):

  • Not for changelog

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

...

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Note

Low Risk
Very small change limited to an exception message in an error-only code path, reducing undefined behavior risk with minimal functional impact.

Overview
Fixes an undefined-behavior error path in ManifestFileIterator::processRow when a manifest entry is EXISTING but has no snapshot_id.

The thrown ICEBERG_SPECIFICATION_VIOLATION message no longer formats an uninitialized resolved_snapshot_id and instead reports the snapshot id as 'null', making the error text accurate and safe.

Written by Cursor Bugbot for commit 92e4dd5. This will update automatically on new commits. Configure here.

Version info

  • Merged into: 26.3.1.707

@clickhouse-gh

clickhouse-gh Bot commented Mar 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [92e4dd5]

Summary: ✅


AI Review

1) Summary

This PR makes a small, targeted fix in ManifestFileIterator::processRow: it removes formatting of an uninitialized resolved_snapshot_id in the EXISTING + missing snapshot_id branch and corrects the exception text to explicitly report snapshot_id 'null'. I did not find correctness, safety, performance, or compliance regressions in the updated code path. High-level verdict: the patch is correct and safe to merge.

2) Missing context (if any)

  • Full CI matrix results were not yet populated in the fetched Praktika report (result_pr.json had no test entries at review time).
  • No benchmark or runtime validation artifacts were attached (reasonable for this error-path-only change).

3) Findings (by severity)

No Blockers or Majors found; the PR looks good.

4) Tests & Evidence

  • Coverage assessment: change is confined to an exception path in Iceberg manifest parsing; no functional path behavior change outside error reporting.
  • Negative/error-handling tests: no new tests in this PR; existing behavior in error branch is now safer (no uninitialized value formatting) and message is accurate.
  • Additional tests to add (optional hardening): add a focused Iceberg manifest parser test with status=EXISTING and snapshot_id=null to assert ICEBERG_SPECIFICATION_VIOLATION message includes snapshot_id 'null'.

5) ClickHouse Compliance Checklist (Yes/No + short note)

  • Data deletions logged? Yes — unchanged; this PR does not alter deletion flows.
  • Serialization formats versioned? Yes (N/A) — no serialization/protocol change.
  • Experimental setting gate present? Yes (N/A) — no new feature/behavior gate required.
  • Settings exposed for constants/thresholds? Yes (N/A) — no new constants introduced.
  • Backward compatibility preserved? Yes — only error formatting/message in a violation branch changed.
  • SettingsHistory.cpp updated for new/changed settings? Yes (N/A) — no settings added/changed.
  • Existing tests untouched (only additions)? Yes — no test removals/relaxations.
  • Docs/user-facing notes updated? Yes (N/A) — no user-facing feature semantics changed.
  • Core-area change got extra scrutiny? Yes — Iceberg table metadata parsing path reviewed carefully.

6) Performance & Safety Notes

  • Hot-path impact: none expected; modified code executes only in a specification-violation branch.
  • Safety: removes undefined behavior risk from using uninitialized resolved_snapshot_id in exception formatting.
  • Benchmarks: not necessary for this patch; if desired, minimal check is a parser micro-test that exercises normal and failing manifest entries.

7) User-Lens Review

  • Behavior is more intuitive: when snapshot_id is absent, the error now says 'null' instead of implying a concrete ID.
  • Error text is actionable and consistent with neighboring diagnostics in the same function.

8) Final Verdict

  • Status: Approve
  • Minimum required actions: none.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Mar 9, 2026
…id` in `ManifestFileIterator`

In `ManifestFileIterator::processRow`, `resolved_snapshot_id` was declared
uninitialized. In the `else if` branch for `EXISTING` entries with no
`parsed_snapshot_id`, the uninitialized variable was passed to `fmt::format`
— undefined behavior. The message also incorrectly implied a snapshot_id
existed by printing its value.

Fix by removing `resolved_snapshot_id` from the format call and hardcoding
`'null'` in the message, consistent with the style of the existing error
message in the same function.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@zlareb1
zlareb1 force-pushed the fix/iceberg-null-snapshot-id-ub branch from 21e8eec to 92e4dd5 Compare March 11, 2026 15:45
@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog and removed pr-bugfix Pull request with bugfix, not backported by default labels Mar 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 83.80% 83.80% +0.00%
Functions 23.90% 23.80% -0.10%
Branches 76.30% 76.30% +0.00%

PR changed lines: PR changed-lines coverage: 0.00% (0/8)
Diff coverage report
Uncovered code

@alexey-milovidov alexey-milovidov self-assigned this Mar 16, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Mar 16, 2026
Merged via the queue into ClickHouse:master with commit d6000db Mar 16, 2026
160 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants