Repository navigation
Fix stack overflow in Avro header parsing on a deep chain of named types - #124053
PedroTadim merged 3 commits into
Conversation
…out recursion Since ClickHouse#121211, `readHeader` in contrib/avro runs `MinEncodedBytesWalker` on every Avro read to bound the declared object count. It recursed through every record field and union branch, following named references, so a schema chaining 100000 named records, each defined inside an array field, overflowed the thread stack while the header was parsed. ClickHouse/avro now walks the schema with its own stack on the heap, in the same order and with the same memo and cycle cut, so the bound does not change for any schema. The test generates such a file and reads it with an explicit structure. The test also checks that the chain still bounds a block's declared object count. Reported in ClickHouse#123998. 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; 2 rounds, 1 finding) plus my own cold review (3 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-11:20261005-152600 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261005-125421 |
|
Workflow [PR], commit [d5432a1] Summary: ✅
AI ReviewSummaryThis PR bumps Final Verdict
LLVM Coverage ReportMeasured on commit d5432a1.
Changed lines: Uncovered code analysis did not run: No coverable C/C++ source files changed (contrib/ is excluded from coverage). Newly covered: +204 lines in 62 files (-139 lines lost coverage) · Details |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 7 s compile time in total, 7 of them have a recent master baseline. |
| # A chain of named records A_k { x: A_(k-1) }. Each one is defined inside its own array field, so the | ||
| # schema nests only a few levels deep, while the last field ["null", A_n] reaches the whole chain. | ||
| python3 -c " | ||
| import json, sys |
There was a problem hiding this comment.
Done in 4a044dc: one generated file and one read instead of two files and three reads (each read of the 100000-record schema took about 70 s under the flaky check's ThreadFuzzer); it still crashes the previous pin and still checks the bound.
The flaky check runs with ThreadFuzzer, which migrates the thread on every mutex operation, so one read of the 100000-record schema took about 70 seconds there, and the test read it three times, over the 180 second limit. With the null codec `count()` takes the same header path whatever `optimize_count_from_files` is, and the file declaring too many records already needs the walk to cover the whole chain without recursion, so the test now generates and reads only that file. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@groeneai I just merged ClickHouse/avro#41, bump the submodule |
ClickHouse/avro#41 was merged as d8ff6d9c9fe4 on the avro master branch. Its tree is identical to the previously pinned PR head fcc115b5c42e, so the compiled code does not change; the pin now points at a commit on the avro master branch instead of the fork branch. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Done in d5432a1: |
Closes: #123998
Related: #121211
Related: ClickHouse/avro#41
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Description
On master since #121211, reading an Avro file whose schema chains 100000 named records
A_k { x: A_(k-1) }crashes with a stack overflow (SIGSEGV) while the header is parsed, on any codec and with anyoptimize_count_from_files. No release is affected: 26.9'scontrib/avropredates the code involved.readHeaderrunsMinEncodedBytesWalker(ClickHouse/avro#34 and ClickHouse/avro#36) on every Avro read to bound the declared object count. It recursed through every record field and union branch. EachA_kis defined inside an array field, which the walk does not descend, so neither its memo nor its cycle cut stops a last field["null", "A_n"]from walking the whole chain on the thread stack.ClickHouse/avro#41 makes the walk iterative, with its own stack on the heap, the same visit order, memo and cycle cut, so the bound is unchanged for every schema. A depth limit would instead reject files that read fine today. This PR bumps
contrib/avroto it.Other surfaces:
GenericDatumis bounded by ClickHouse/avro#39 and building theAvroDeserializerchecks the stack per level. Schema inference (DESCwithout a structure) also recurses through such a chain; that is pre-existing and not changed here.Validation:
05325_avro_deep_named_type_chaingenerates such a file, reachingA_nthrough a required field, with a block that declares more records than its payload can hold. The previous pin crashes (exit 139) while parsing its header; this one rejects the block, which a walk that stopped at named types would accept. A temporary build computing both the recursive and the iterative bound on every read found no difference over 428 generated schemas (DAGs, cycles, unions, every codec) and the Avro and Iceberg stateless tests.Workflow [PR]
Sync PR [sync-upstream/pr/124053]
Version info
26.10.1.1679-master(included in26.10and later)