Repository navigation
Check for stack overflow in Avro reader - #102417
Conversation
|
Workflow [PR], commit [3c7fb12] Summary: ❌
AI ReviewSummaryThis PR adds stack-depth guards for Avro schema handling by passing Findings❌ Blockers
Final VerdictStatus: ❌ Block
|
| /// prevent stack overflow on deeply nested schemas (e.g. crafted inputs with | ||
| /// thousands of nested arrays/records). Real-world schemas rarely exceed 10-20 | ||
| /// levels, so 256 is more than enough. | ||
| static constexpr size_t MAX_AVRO_SCHEMA_DEPTH = 256; |
There was a problem hiding this comment.
❌ This introduces a backward-incompatible hard limit for existing Avro inputs/schemas (>256 nesting) with no configurable fallback.
Before this change, acceptance depended on available stack; after this change, those inputs are rejected unconditionally at schema parse time. Per ClickHouse compatibility rules, new enforcement on previously accepted data should be gated (setting/compatibility) or at least made configurable.
Please add an input format setting (for example input_format_avro_max_schema_depth) and wire it here instead of a fixed static constexpr value. That keeps the safe default while allowing compatibility for existing workloads.
There was a problem hiding this comment.
Addin the setting will lead to a security issue - setting high value to the limit can lead to a stack overflow. We have to use hard limit. 256 is more than enough for real use cases
There was a problem hiding this comment.
This is still a backward-compatibility break for existing Avro inputs that are deeper than 256 levels.
The current code hard-rejects these schemas via MAX_AVRO_SCHEMA_DEPTH in both AvroRowInputFormat and ConfluentSchemaRegistry, while previous versions could still process them when stack limits allowed it. Per ClickHouse compatibility rules, new validation on previously accepted data should be gated (for example via an input-format setting / compatibility) rather than hard-coded.
Please make this limit configurable (safe default is fine), so existing workloads have an explicit compatibility path.
…overflow-avro-reader
|
Bugfix validation (functional tests) - it reproduces only under asan |
…-reader # Conflicts: # src/Processors/Formats/Impl/AvroRowInputFormat.cpp
|
This was fixed by #105146. Let's update the branch. |
The previous commit only constrained schema depth in `AvroRowInputFormat` and `ConfluentSchemaRegistry`. The same unbounded schema-parse path existed in the Iceberg Avro readers: `AvroForIcebergDeserializer` and `forEachAvroEntry` in `Iceberg/Utils`. Move `MAX_AVRO_SCHEMA_DEPTH` into `AvroRowInputFormat.h` and apply it to the two Iceberg call sites so the stack-overflow mitigation covers every Avro reader entry point. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
… stack-overflow-avro-reader
LLVM Coverage Report
Changed lines: 100.00% (34/34) · Uncovered code |
Cherry pick #102417 to 26.4: Check for stack overflow in Avro reader
Cherry pick #102417 to 25.8: Check for stack overflow in Avro reader
Cherry pick #102417 to 26.2: Check for stack overflow in Avro reader
Cherry pick #102417 to 26.3: Check for stack overflow in Avro reader
Backport #102417 to 26.4: Check for stack overflow in Avro reader
The cherry-pick of #102417 resolved the avro submodule conflict to the wrong commit (477ed40c656b, old API) instead of 3b5d52bdf9f9 (which adds the `max_depth` parameter to `DataFileReaderBase` and `compileJsonSchemaFromString`). Co-Authored-By: Claude Opus 4.6 <[email protected]>
The cherry-pick of #102417 resolved the avro submodule conflict to the wrong commit (477ed40c656b, old API) instead of 3b5d52bdf9f9 (which adds the `max_depth` parameter to `DataFileReaderBase` and `compileJsonSchemaFromString`). Co-Authored-By: Claude Opus 4.6 <[email protected]>
The cherry-pick of #102417 resolved the avro submodule conflict to the wrong commit (477ed40c656b, old API) instead of 3b5d52bdf9f9 (which adds the `max_depth` parameter to `DataFileReaderBase` and `compileJsonSchemaFromString`). Co-Authored-By: Claude Opus 4.6 <[email protected]>
Backport #102417 to 26.3: Check for stack overflow in Avro reader
Backport #102417 to 26.2: Check for stack overflow in Avro reader
Backport #102417 to 25.8: Check for stack overflow in Avro reader
…2417 Backport ClickHouse#102417 to 26.4: Check for stack overflow in Avro reader
`AvroSchemaReader::avroNodeToDataTypeImpl` follows named type references, so its recursion depth is the length of the reference chain, not the JSON nesting that contrib/avro bounds with `MAX_AVRO_SCHEMA_DEPTH`. A valid file whose schema chains 100000 named records, each defined in its own array field, made `DESC file(..., Avro)` recurse ~200000 frames and overflow the stack (SIGSEGV on 26.8.18.2 server and on master, after ~35 s and 13 GB). The per-level `checkStackSize()` added by ClickHouse#102417 ended up in the non-recursive wrapper `avroNodeToDataType` when ClickHouse#102853 split the recursion into `avroNodeToDataTypeImpl`, so it ran once per root column. Count the recursion depth against `max_parser_depth` (0 = unlimited) and throw `TOO_DEEP_RECURSION`, as ClickHouse#107341 does for MsgPack, BSON, ORC, Parquet and JSON schema inference, and keep `checkStackSize()` per level as a backstop for a raised or unlimited limit. The limit is passed by all three callers (schema inference, the Variant read path and the Iceberg manifest reader), and `max_parser_depth` is added to the Avro/AvroConfluent schema cache key, so a schema inferred under a higher limit is not served to a query with a lower one (same as a839800 did for ORC). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Check for stack overflow in Avro reader during nested types deserialization.
Documentation entry for user-facing changes
Version info
26.4.3.38,26.3.11.34,26.2.19.42