Repository navigation
Bound the recursion in several parsers and schema readers - #115700
Conversation
|
Workflow [PR], commit [6883c59] Summary: ✅
AI ReviewSummaryThis PR adds stack-depth guards to several user-controlled recursive paths ( Findings❌ Blockers
Final VerdictChanges requested. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 98/109 (89.91%) · Uncovered code |
…no-fasttest` `clang-tidy` requires `const auto *` for the RapidJSON array iterator, the style check requires a `-WithMemoryTracking` container in `src/Functions`, and `JSONMergePatch` is not available in the fast test build, which is built without RapidJSON.
… regressions The CapnProto nesting check was applied only to the entry schema file, but `parseFromDirectory` parses the files it `import`s with the same recursive parser, so a shallow wrapper schema could still smuggle a deeply nested one in and exhaust the thread stack. Walk the import graph and check every file. Add the regression tests the review asked for: `EXECUTE` with an argument that is not a literal over the PostgreSQL wire protocol, and a deeply nested `CURSOR` clause of `STREAM`.
|
🕵 Addressed the AI review:
Also fixed the |
|
|
||
| capnp::StructSchema CapnProtoSchemaParser::getMessageSchema(const FormatSchemaInfo & schema_info) | ||
| { | ||
| checkCapnProtoSchemaNestingDepth(schema_info.schemaDirectory(), schema_info.schemaPath()); |
There was a problem hiding this comment.
This still leaves a stack-exhaustion path open for actual FORMAT CapnProto use. getMessageSchema() now rejects the entry file and its imports, but both CapnProtoRowInputFormat and CapnProtoRowOutputFormat immediately build a CapnProtoSerializer afterwards, and that code keeps recursing through nested LIST / STRUCT / Nullable / Map types without any checkStackSize() (src/Formats/CapnProtoSerializer.cpp:848, 933, 1042, 1200, 1365, 1415). A deeply nested List(List(...)) schema therefore still reaches unbounded recursion as soon as someone actually does INSERT / SELECT FORMAT CapnProto, even though DESC format() is safe now. This needs the same depth guard on the serializer-construction / recursive row I/O path, and the regression should instantiate real CapnProto input/output rather than only schema inference.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Object file sizes10 object files changed (+62.98 KiB total), 0 added.
737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units13 translation units recompiled, 29 s compile time in total, 13 of them have a recent master baseline. |
|
@alexey-milovidov — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
Cherry pick #115700 to 25.8: Bound the recursion in several parsers and schema readers
Cherry pick #115700 to 26.3: Bound the recursion in several parsers and schema readers
Cherry pick #115700 to 26.5: Bound the recursion in several parsers and schema readers
…oint` On 26.5, `parseWKBFormat` does not support the `MultiPoint` geometry (WKB type 4), so the type-4 query fails with `BAD_ARGUMENTS` before any recursion happens. Drop that line and keep the `MultiLineString`/`MultiPolygon` (types 5/6) checks, which exercise the backported `checkStackSize` guard and return `TOO_DEEP_RECURSION`. Same adaptation as the sibling backports of #115700. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=116320&sha=latest&name_0=BackportPR PR: #116320 Co-Authored-By: Claude Fable 5 <[email protected]>
Backport #115700 to 26.5: Bound the recursion in several parsers and schema readers
Backport #115700 to 25.8: Bound the recursion in several parsers and schema readers
Backport #115700 to 26.3: Bound the recursion in several parsers and schema readers
Backport #115700 to 26.6: Bound the recursion in several parsers and schema readers
Backport #115700 to 26.7: Bound the recursion in several parsers and schema readers
…rsers and schema readers
Several places recurse over data or over text that comes from the query or from a file, without
bounding the recursion, so a deeply nested input exhausts the thread stack and takes the whole
server down instead of failing the query:
readWKBand friends:Multi*geometries contain nested geometries, and the existing limit onthe number of elements does not bound the nesting, because every level can hold a single element.
JSONMergePatch: parsing is iterative, but copying, merging and serializing the documents recurseover the tree.
parseRemoteDescription(url,remote,cluster,mysql,postgresql, ...): nested bracesare expanded recursively, and
max_addressesbounds the number of generated addresses, not thenesting depth.
CURSORclause parser ofSTREAM: the helper recurses directly instead of going throughIParserBase::parse, somax_parser_depthwas not in effect.of its own, and it runs on a schema that can be passed inline with
format_schema_source='string'.In addition,
ParserExecutedereferenced the result of a cast toASTLiteralwithout checking it,so an
EXECUTEstatement with a non-literal argument dereferenced a null pointer.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix server crashes on deeply nested input in
readWKB,JSONMergePatch, the address parser of theurl/remote/cluster/mysql/postgresqltable functions, theCURSORclause parser and the CapnProto schema parser. Fix a crash in the parser of theEXECUTEstatement when an argument is not a literal.Workflow [PR]
Sync PR [sync-upstream/pr/115700]
Version info
26.8.1.1928(included in26.8and later)26.7.6.36,26.6.4.46,26.3.26.2