Repository navigation
Fix server crash on a deeply nested Field in a binary encoded type - #122667
Conversation
`decodeField` recursed into itself for the container fields with no bound of any kind, and the nesting depth is a property of the data rather than of the query: a `Dynamic` value carries its own type, and the parameters of an `AggregateFunction` type are Fields. A deeply nested parameter therefore ran past the stack guard page instead of failing the query. Add `checkStackSize` to the recursive branches of both directions, matching what `FieldVisitorWriteBinary` and the other Field visitors already do, so deep values are reported as `TOO_DEEP_RECURSION`. `decodeDataTypeImpl` counts decoded nodes against `input_format_binary_max_type_complexity`, but handed off to `decodeField` without the counter, so the limit stopped at the type/field boundary and a tiny type header could still expand into an arbitrary amount of work. Thread the counter through `decodeAggregateFunction` into `decodeField` so that Field nodes are charged to the same budget. The single argument `decodeField` keeps its signature and stays unlimited, which preserves the property that reading already stored values is never limited by the setting. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
# Conflicts: # src/Core/FormatFactorySettings.h
05219 is taken by several tests on master now. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [6010df9] Summary: ✅
AI ReviewSummaryThis PR closes the unbounded-recursion hole in binary Findings💡 Nits
Final VerdictOne nit to fix in the user-facing setting description; otherwise the recursion and complexity-limit changes look correct. LLVM Coverage ReportMeasured on commit 6010df9.
Changed lines: Changed C/C++ lines covered: 72/72 (100.00%) · Uncovered code |
The two guards race: whichever of the node counter and the stack check is reached first decides the error code, and the stack allowance depends on the build - Thread Sanitizer permits only 5% of the stack, so a thousand decode frames exhaust it and the query fails with `TOO_DEEP_RECURSION` instead of the expected `INCORRECT_DATA`. Lower the budget in the two queries that assert the limit so it trips after about ten nodes, which no build can turn into an exhausted stack. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
| )", 0) \ | ||
| DECLARE(UInt64, input_format_binary_max_type_complexity, 1000, R"( | ||
| Max type nodes when decoding binary types (not depth, but total count). `Map(String, UInt32)` = 3 nodes. Protects against malicious inputs. 0 = unlimited. | ||
| Max type nodes when decoding binary types (not depth, but total count). `Map(String, UInt32)` = 3 nodes. Parameters of `AggregateFunction` types count as one node per value, including nested ones. Protects against malicious inputs. 0 = unlimited. |
There was a problem hiding this comment.
input_format_binary_max_type_complexity now applies to SimpleAggregateFunction too, not only AggregateFunction. Both BinaryTypeIndex::AggregateFunction and BinaryTypeIndex::SimpleAggregateFunction decode through decodeAggregateFunction, and the new regression test in 05291_binary_encoded_field_deep_recursion.sql is actually exercising the SimpleAggregateFunction case.
As written, system.settings will tell users that only AggregateFunction(...) payloads are charged here, which is now inaccurate. Please mention both surfaces in this description.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units21 translation units recompiled, 95 s compile time in total, 21 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.17 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
Cherry pick #122667 to 26.3: Fix server crash on a deeply nested Field in a binary encoded type
Cherry pick #122667 to 26.7: Fix server crash on a deeply nested Field in a binary encoded type
Cherry pick #122667 to 26.8: Fix server crash on a deeply nested Field in a binary encoded type
Cherry pick #122667 to 26.9: Fix server crash on a deeply nested Field in a binary encoded type
…n a binary encoded type
…n a binary encoded type
…n a binary encoded type
…n a binary encoded type
Backport #122667 to 26.8: Fix server crash on a deeply nested Field in a binary encoded type
Backport #122667 to 26.7: Fix server crash on a deeply nested Field in a binary encoded type
Backport #122667 to 26.9: Fix server crash on a deeply nested Field in a binary encoded type
Backport #122667 to 26.3: Fix server crash on a deeply nested Field in a binary encoded type
Decoding a binary encoded
Fieldrecursed into itself for the container fields with no bound of any kind. The nesting depth is a property of the data rather than of the query — aDynamicvalue carries its own type, and the parameters of anAggregateFunctiontype are Fields — so a deeply nested parameter ran past the stack guard page and terminated the server process instead of failing the query. It was reachable on the ordinary read path of aDynamiccolumn, so a singleINSERT ... FORMAT RowBinarywas enough.Both directions of the binary Field encoding now call
checkStackSizein their recursive branches, matching whatFieldVisitorWriteBinaryand the other Field visitors already do, so deep values are reported asTOO_DEEP_RECURSION.In addition,
decodeDataTypeImplcounts decoded nodes againstinput_format_binary_max_type_complexitybut handed off todecodeFieldwithout the counter, so the limit stopped at the type/field boundary and a small type header could still expand into an arbitrary amount of work. The counter is now threaded throughdecodeAggregateFunctionintodecodeField, so Field nodes are charged to the same budget. The single argumentdecodeFieldkeeps its signature and stays unlimited, which preserves the property (pinned by04303_binary_max_type_complexity_input_only) that reading already stored values is never limited by the setting.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a server crash caused by unbounded recursion when decoding a deeply nested value inside a binary encoded type, for example an
AggregateFunctionparameter in aDynamicvalue read fromRowBinaryorNative.Workflow [PR]
Sync PR [sync-upstream/pr/122667]
Version info
26.10.1.996-master(included in26.10and later)26.9.9.23,26.8.16.28,26.7.20.19,26.3.40.12