Skip to content

Fix crash on invalid Iceberg manifest-list entries - #122829

Merged
arsenmuk merged 1 commit into
masterfrom
arsenmuk/malformed-avro
Sep 30, 2026
Merged

arsenmuk merged 1 commit into
masterfrom
arsenmuk/malformed-avro

Conversation

@arsenmuk

@arsenmuk arsenmuk commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

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

Fix validation of Iceberg manifest-list entries during writes.


Workflow [PR]
Sync PR [sync-upstream/pr/122829]

Version info

  • Merged into: 26.10.1.1047-master (included in 26.10 and later)
  • Backported to: 26.9.7.8, 26.8.15.15, 26.7.19.6, 26.3.40.9

@clickhouse-gh

clickhouse-gh Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0f11646]

Summary: ✅


AI Review

Summary

This PR hardens one Iceberg manifest-list crash path by rejecting non-record Avro roots and validating several required fields before copying them into a rewritten manifest list. The remaining blocker is that the carry-forward path still copies the rest of each avro::GenericDatum verbatim, so ClickHouse can still commit an invalid manifest list instead of rejecting it.

Findings

❌ Blockers

  • [src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp:970] Carried-forward manifest-list fields are copied schema-blind. GenericRecord assignment does not validate against the destination field schema, and GenericWriter serializes according to the copied datum's own isUnion() / type(). For tables upgraded externally from Iceberg format-version 1 to 2, this rewrites valid v1 ["null", int/long] count fields into a v2 manifest list that declares plain int / long, emitting the old union branch tag and corrupting the new manifest list. The same helper also propagates malformed content, sequence_number, partitions, and other optional fields instead of rejecting them.
    Suggested fix: decode each carried-forward field into the target schema explicitly, reusing setVersionedField-style logic or a schema-aware copier that unwraps unions and validates nested types before assignment.
Tests
  • The new stateless test only corrupts the file's top-level schema (array<int>). It does not cover the schema-aware carry-forward path above, so it would still pass if v1 -> v2 union fields or malformed optional fields were copied into the rewritten manifest list unchanged.
Final Verdict

Changes requested. The crash is fixed for one malformed-root case, but the carry-forward rewrite path can still emit invalid manifest lists because optional and versioned fields are copied without re-encoding against the destination schema.

LLVM Coverage Report

Measured on commit 0f11646.

Metric Baseline Current Δ
Lines 87.90% 87.90% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 79.30% 79.30% +0.00%

Changed lines: Changed C/C++ lines covered: 35/58 (60.34%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Sep 29, 2026
Iceberg::f_added_snapshot_id,
static_cast<int>(old_added_snapshot_id_entry.type()));

new_entry.field(f_added_snapshot_id) = old_added_snapshot_id_entry.value<Int64>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The carry-forward path still bypasses the target manifest-list schema for every field copied through add_field_to_datum. avro::GenericRecord assignment does not validate the source GenericDatum against new_entry's field schema, and avro::GenericWriter serializes according to the copied datum's own isUnion() / type() rather than the destination field type.

That breaks a real compatibility path we already support: StatelessMetadataFileGetter explicitly handles tables whose Iceberg format-version was upgraded externally from v1 to v2 while older v1 manifest lists are still referenced. In that case added_files_count / existing_* / deleted_* / *_rows_count arrive here as ["null", T] unions, but this code copies them straight into a v2 record that declares plain int / long, so the rewritten manifest list is emitted with the old union branch tag and becomes invalid. The same blind copy also propagates malformed content / sequence_number / partitions payloads instead of rejecting them, so the "validate invalid manifest-list entries during writes" contract is still open for those fields.

Please re-materialize carried-forward fields against new_entry's schema instead of copying GenericDatum wholesale, e.g. with a schema-aware helper in the style of setVersionedField that unwraps nullable unions and throws on any source type that cannot be represented by the target field.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A separate issue in the same file, can be fixed later.

@clickhouse-gh

clickhouse-gh Bot commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 0f1164630 with master 001b6e36e (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

5 object files changed (+29.03 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp.o 972.25 KiB 995.66 KiB +23.40 KiB (+2.41%)

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

8 translation units recompiled, 34 s compile time in total, 8 of them have a recent master baseline.

Job report

@asya-ch asya-ch self-assigned this Sep 29, 2026
@arsenmuk
arsenmuk added this pull request to the merge queue Sep 30, 2026
Merged via the queue into master with commit 1a044b1 Sep 30, 2026
149 checks passed
@arsenmuk
arsenmuk deleted the arsenmuk/malformed-avro branch September 30, 2026 08:10
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 30, 2026
@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 30, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 30, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 30, 2026
Backport #122829 to 26.9: Fix crash on invalid Iceberg manifest-list entries
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 30, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 30, 2026
Backport #122829 to 26.8: Fix crash on invalid Iceberg manifest-list entries
PedroTadim added a commit that referenced this pull request Oct 1, 2026
Backport #122829 to 26.7: Fix crash on invalid Iceberg manifest-list entries
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Oct 2, 2026
PedroTadim added a commit that referenced this pull request Oct 2, 2026
Cherry pick #122829 to 26.3: Fix crash on invalid Iceberg manifest-list entries
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 2, 2026
PedroTadim added a commit that referenced this pull request Oct 2, 2026
Backport #122829 to 26.3: Fix crash on invalid Iceberg manifest-list entries
@clickhouse-gh clickhouse-gh Bot added comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... and removed comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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.

5 participants