Repository navigation
Bound the nesting depth of building and reading a GenericDatum - #39
Merged
Merged
Conversation
A named type may reference itself, and both recursions follow the reference
without any limit:
- `GenericDatum::init` builds every field of a record eagerly (and the first
branch of a union), so a schema whose cycle has no terminating branch, such
as `A{b: B{a: A}}`, recursed forever in the `GenericRecord` constructor;
- `GenericReader::read` recurses once per nesting level of the data, so a
terminating cycle such as `A{next: ["null", "A"]}` overflowed the stack on a
value nested a million levels deep.
`maxSchemaDepth_` does not help: it bounds the textual nesting of the schema
JSON, and a self-reference is one shallow lookup there.
Both now throw an `Exception` beyond `GenericDatum::maxNestingDepth` (256, the
schema depth limit ClickHouse passes to `DataFileReaderBase`). ClickHouse
builds `GenericDatum` only for Iceberg manifest lists and its own manifest
schemas, which nest a few levels.
Reported in ClickHouse/ClickHouse#123044 (an Iceberg INSERT carrying forward a
crafted manifest list crashed the server).
PedroTadim
approved these changes
Oct 2, 2026
groeneai
added a commit
to groeneai/ClickHouse
that referenced
this pull request
Oct 2, 2026
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]>
groeneai
added a commit
to groeneai/ClickHouse
that referenced
this pull request
Oct 5, 2026
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A named type may reference itself, and both
GenericDatumconstruction andGenericReader::readfollow the reference with no limit:GenericDatum::initbuilds every record field (and the first branch of a union) eagerly, soA{b: B{a: A}}recursed forever in theGenericRecordconstructor;GenericReader::readrecurses once per nesting level of the data, soA{next: ["null", "A"]}overflowed the stack on a value nested 1,000,000 levels deep.maxSchemaDepth_(#31) bounds only the textual nesting of the schema JSON, and a self-reference is one shallow lookup there.Both now throw
avro::ExceptionbeyondGenericDatum::maxNestingDepth(256). The branch is based on ClickHouse's current pin (6640c55c752e), so bumping to it carries no other fork change.Fixes the crash in ClickHouse/ClickHouse#123044, bumped in ClickHouse/ClickHouse#123084. Checked with ClickHouse built against this commit: the four crashing cases (the required cycle, and nullable, array and map cycles nested 1,000,000 levels deep) now fail with this exception instead of SIGSEGV, and 88 Avro/Iceberg stateless tests give the same results as before, except the new one.