Repository navigation
Conversation
…reader
An INSERT (or ALTER DROP PARTITION, OPTIMIZE, mutation) into an Iceberg table carries the
parent snapshot's manifest list forward through `Iceberg::forEachAvroEntry`, which builds an
`avro::GenericDatum` from the file's own writer schema. avro-cpp constructs and reads
`GenericDatum` recursively without any depth limit, so a manifest list whose schema contains a
named record that reaches itself killed the process with a stack overflow (SIGSEGV):
- a required cycle, `A{b: B{a: A}}`, recursed forever in the `GenericRecord` constructor;
- a nullable cycle, `A{next: ["null", "A"]}`, constructed fine but recursed once per nesting
level of the data in `GenericReader::read`.
The read path already rejects such a schema: `AvroForIcebergDeserializer` calls
`AvroSchemaReader::avroNodeToDataType`, whose `seen_names` check throws "Recursive Avro schema
is not supported". The carry-forward re-reads the raw file and never went through it. That is
reachable when the reader's result for the same path comes from the metadata files cache (the
file was replaced after it was cached), or when a commit conflict makes the retry carry forward
another writer's snapshot.
Run the same `avroNodeToDataType` on the schema before building the `GenericDatum`, and rethrow
its error as `ICEBERG_SPECIFICATION_VIOLATION` with the file name, like the root-type check
next to it. The writer now accepts exactly the manifest-list schemas the reader accepts. Both
faces are rejected on the schema, before any data is read.
Closes ClickHouse#123044
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding) and my own review (1 finding). Nothing blocking.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20260930-141900 |
|
Workflow [PR], commit [5b9e8ef] Summary: ✅ AI ReviewSummaryThis PR now reduces to a focused stateless regression test for the two Findings
Final Verdict
|
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units32 translation units recompiled, 183 s compile time in total, 32 of them have a recent master baseline. |
| try | ||
| { | ||
| /// avro-cpp builds and reads `GenericDatum` recursively without a depth limit, so a recursive schema must not reach it. | ||
| AvroSchemaReader::avroNodeToDataType(reader.readerSchema().root()); |
There was a problem hiding this comment.
@groeneai it seems the fix should go to ClickHouse's Avro fork. Is this a regression of something I merged there?
There was a problem hiding this comment.
No, it is not a regression from the fork. The unbounded recursion is upstream avro-cpp code that the fork never modified: GenericRecord's constructor builds a GenericDatum per field, and GenericReader::read recurses once per nesting level (the last change to GenericDatum.cc/Generic.cc is from 2019, and apache/avro main is the same). The official 26.8.10.6 and 26.9.1.1629 images crash on the same repro, and both pin contrib/avro at 7b7f6a5bc42e, which is older than ClickHouse/avro#33, ClickHouse/avro#34 and ClickHouse/avro#37. ClickHouse/avro#31 bounds only the textual nesting of the schema, and a self-referencing named type passes it. The minEncodedBytes walk from ClickHouse/avro#34 (not in master's pin yet) is capped at 64, so it adds no new path.
Agreed on the location. I'll bound the nesting depth of GenericDatum construction and GenericReader::read in ClickHouse/avro (throwing avro::Exception), then bump contrib/avro here and drop the Utils.cpp check.
There was a problem hiding this comment.
Done: ClickHouse/avro#39 makes GenericDatum construction and GenericReader::read throw avro::Exception beyond 256 nesting levels, and 395ebf9 bumps contrib/avro to it and drops the Utils.cpp check. The fork branch is based on the current pin, so the bump carries nothing else. Without it the required cycle and the nullable, array and map cycles nested 1,000,000 levels deep all crash; with it all four fail with AVRO_EXCEPTION. 05296 now also covers the deep case.
Per review, bound the recursion where it happens: the `contrib/avro` bump makes `GenericDatum` construction and `GenericReader::read` throw beyond 256 nesting levels, so `forEachAvroEntry` no longer needs to predict avro-cpp's recursion by running `AvroSchemaReader::avroNodeToDataType` on the schema first. The bump is based on the current pin, so it carries no other fork change. The test now also covers a nullable recursive row nested 1,000,000 levels deep, which overflowed the stack in `GenericReader::read`.
…OLATION
With the depth bound in contrib/avro, a recursive or too deeply nested
manifest list failed the Iceberg write with a bare `AVRO_EXCEPTION`
("Cannot build a datum nested deeper than 256 levels") that did not name the
file. Wrap avro errors raised while reading the manifest list with the file
name and the Iceberg error code, as the root-type check next to it already
does and as the reader path (`AvroForIcebergDeserializer`) does for the same
files.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@groeneai I just merged ClickHouse/avro#39 can you bump the avro submodule in this PR? |
|
I did not bump it yet. Moving the pin to avro master ( Measured with
The current pin |
|
@groeneai I Just merged ClickHouse/avro#36 in the avro repo, do the bump please |
Moves the pin from the ClickHouse/avro#39 commit to the current master (merge of ClickHouse/avro#36). Besides ClickHouse#39 (already pinned), this brings in ClickHouse#34 (bound the declared object count by a schema-derived minimum record size), ClickHouse#36 (memoise that walk, so it terminates on recursive schemas) and ClickHouse#37 (test fix). Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Done in 8b07686: |
| while (reader.read(datum)) | ||
| callback(datum); | ||
| } | ||
| catch (const avro::Exception & e) |
There was a problem hiding this comment.
This still only rejects recursion when GenericDatum construction or reader.read actually walks into the cycle. That leaves a real gap versus the current read path: a manifest-list schema that keeps the required Iceberg fields but adds an extra nullable recursive field (for example ['null', 'Self'] with all rows on the null branch) will pass here, because GenericUnion initializes branch 0 only and the carry-forward code ignores extra fields. The write then succeeds and rewrites a snapshot that AvroSchemaReader::avroNodeToDataType still rejects up front as a recursive schema.
Can we keep a schema-level recursive-schema check before building the generic reader (or otherwise align the reader path), so every recursive manifest-list schema fails deterministically with ICEBERG_SPECIFICATION_VIOLATION?
CI finish ledger - 8b07686Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
All 146 check runs completed, Session id: cron:our-pr-ci-monitor:20261003-050056 |
| while (reader.read(datum)) | ||
| callback(datum); | ||
| } | ||
| catch (const avro::Exception & e) |
There was a problem hiding this comment.
@groeneai we don't need the try catch? Just let throw the avro exception
There was a problem hiding this comment.
Right, removed in 60e27e3: forEachAvroEntry is back to its master version, so the error is now AVRO_EXCEPTION ("Cannot build/read a datum nested deeper than 256 levels"), and 05296 expects that.
|
@groeneai maybe I messed up in ClickHouse/avro#39. Is it difficult to add |
|
Not difficult, but it cannot be a direct call: I don't think ClickHouse/avro#39 was a mistake, though:
I'd keep it as is. If you prefer the hook, I'll open it in ClickHouse/avro and bump it here. |
Drop the function-try-block that rethrew avro::Exception as
ICEBERG_SPECIFICATION_VIOLATION, as requested in review: the error from
the ClickHouse/avro depth bound is now reported as AVRO_EXCEPTION
("Cannot build/read a datum nested deeper than 256 levels").
forEachAvroEntry is back to its master version, and 05296 expects
AVRO_EXCEPTION for the two recursive cases.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
| # A manifest list with a recursive Avro schema must be rejected by an INSERT into an Iceberg table, not crash. | ||
| # `clickhouse local` contains the pre-fix fatal signal to a short-lived subprocess. | ||
|
|
||
| CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) |
There was a problem hiding this comment.
@groeneai trim the test and merge with master, the bump is no longer needed?
There was a problem hiding this comment.
Yes, the bump is no longer needed: #121211 moved master's contrib/avro to the same a56fc2f, so after merging master (06b76e9) the PR diff is only the test. Trimmed it in 5b9e8ef to the two cases that crashed (required cycle, and a nullable cycle nested 1,000,000 levels), each checking its own AVRO_EXCEPTION depth error. Since the fix itself is already on master, I changed the category to CI Fix or Improvement.
…ve-manifest-list-schema
Keep only the recursive record (fails building the datum) and the 1,000,000-level nullable cycle (fails reading it), and assert which of the two ClickHouse/avro#39 depth checks fires, with its error code. Drop the controls and the server liveness probe; the test uses only `clickhouse local`. The contrib/avro bump is no longer part of this PR: master already pins the same commit since ClickHouse#121211. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
We no longer need this PR. |
Closes: #123044
Related: #122829
Related: ClickHouse/avro#39
Related: ClickHouse/avro#36
Related: #121211
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Description
On 26.8.10.6 and 26.9.1.1629, an
INSERTinto an Iceberg table (allow_insert_into_iceberg = 1) whose current snapshot's manifest list has a recursive Avro schema, such asA{b: B{a: A}}, orA{next: ["null", "A"]}with deeply nested data, crashes with a stack overflow (SIGSEGV):Iceberg::forEachAvroEntrycarries the list forward through avro-cpp'sGenericDatum, which is built and read recursively.The fix is ClickHouse/avro#39, which makes
GenericDatumconstruction andGenericReader::readthrow beyond 256 nesting levels. It is on master through thecontrib/avrobump in #121211 (the same commit this PR used to pin), so this PR now only adds the regression test.Test.
05296_iceberg_recursive_manifest_list_writerreplaces a cached manifest list with a required cycle, which fails building the datum, and with a nullable cycle nested 1,000,000 levels deep, which fails reading it, and checks theAVRO_EXCEPTIONdepth error of each. With the previouscontrib/avropin both cases crashclickhouse-local(exit 139).🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/123084]