Repository navigation
Fix CapnProto schema depth check bypass through comments and backtick text lines - #125487
Merged
alexey-milovidov merged 1 commit intoOct 14, 2026
Conversation
… text lines checkCapnProtoSchemaNestingDepth re-tokenizes a CapnProto schema before the recursive Cap'n Proto parser runs, to bound bracket nesting and to follow imports. Its tokenizer diverged from the Cap'n Proto lexer in three ways, each of which let a deeply nested schema reach the parser unchecked and overflow the stack (SIGSEGV): - A `#` comment or a UTF-8 byte order mark between `import` and its path cleared the pending `import` (the lexer allows both between any tokens), so the imported file was never checked (ClickHouse#116032). - Backtick text lines (to the first `\r` or `\n`, value plus `\n`) were unknown: a `"` inside one opened a fake literal that hid real brackets, a `#` inside one hid the rest of the `\n` line although the lexer ends the token at `\r`, a backtick import path was never followed, and brackets inside one were counted, so a valid schema could be rejected. - Escapes in a quoted import path were decoded differently (`\x2e` became `x2e`), so the checked path was not the one Cap'n Proto opened. Comments and byte order marks now terminate the word like whitespace does, backtick lines are handled as text literals and followed as import paths, and `"..."` is lexed with kj::parse::doubleQuotedString, the parser the lexer itself uses, so escapes decode identically. When kj cannot lex the literal (e.g. a `0x"..."` data literal spanning lines, which is valid), the previous skip-to-next-quote loop runs unchanged, so the scan never stops early. Closes ClickHouse#116032 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
Author
Internal second-model review (click to expand)Own cold review + Gate B (codex) on
|
Collaborator
Author
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261012-184400 |
Contributor
|
Workflow [PR], commit [19ad921] Summary: ✅
AI ReviewSummaryThis PR tightens Final Verdict
|
alexey-milovidov
approved these changes
Oct 14, 2026
Merged
via the queue into
ClickHouse:master
with commit Oct 14, 2026
5c2d6ef
177 of 178 checks passed
This was referenced Oct 14, 2026
clickhouse-gh Bot
added a commit
that referenced
this pull request
Oct 14, 2026
Backport #125487 to 26.9: Fix CapnProto schema depth check bypass through comments and backtick text lines
clickhouse-gh Bot
added a commit
that referenced
this pull request
Oct 14, 2026
Backport #125487 to 26.8: Fix CapnProto schema depth check bypass through comments and backtick text lines
alexey-milovidov
added a commit
that referenced
this pull request
Oct 15, 2026
Backport #125487 to 26.3: Fix CapnProto schema depth check bypass through comments and backtick text lines
clickhouse-gh Bot
added a commit
that referenced
this pull request
Oct 15, 2026
Backport #125487 to 26.7: Fix CapnProto schema depth check bypass through comments and backtick text lines
strtgbb
pushed a commit
to Altinity/ClickHouse
that referenced
this pull request
Oct 15, 2026
…bypass through comments and backtick text lines
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.
Closes: #116032
Related: #115700
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a stack overflow crash on a deeply nested CapnProto schema that the nesting depth check missed: a comment or a byte order mark between
importand its path, an escape sequence in the import path, or a backtick text line. A backtick text line with many brackets is no longer rejected as nested too deeply.Description
On 26.8.18.2 and 26.9.11.2, a CapnProto schema that puts a comment between
importand its path, or has a backtick text line containing", makesDESC format(CapnProto, '')die with SIGSEGV (stack overflow in the Cap'n Proto parser) instead of failing withThe CapnProto schema is nested too deeply. Withformat_schema_source = 'string'this is reachable from one query.checkCapnProtoSchemaNestingDepth(#115700) re-tokenizes the schema to count nesting and follow imports before the recursive parser runs, but it tokenized three things differently from the Cap'n Proto lexer:#comments and UTF-8 byte order marks between tokens cleared the pendingimport, so the imported file was not checked;"or#inside one hid the brackets after it, a backtick import path was not followed, and brackets inside one were counted, so a valid schema could be rejected;\x2e,\056) were decoded differently, so the checked path was not the opened one.The change keeps the pending
importacross comments and byte order marks, handles backtick lines as text literals (ended by\ror\n, with the trailing\nCap'n Proto adds), and lexes"..."with Cap'n Proto's ownkj::parse::doubleQuotedString, falling back to the previous skip loop when that fails (e.g. a multi-line0x"..."data literal), so the scan never stops early.The new test has one case per form; on master the six bypass cases crash and the brackets case is rejected. It passes 50 randomized runs, the existing CapnProto tests pass, and no upstream Cap'n Proto schema changes its result. A chain of individually shallow imports (the open risk in the issue) is not addressed here.
Workflow [PR]
Sync PR [sync-upstream/pr/125487]
Version info
26.10.1.2350-master(included in26.10and later)26.9.20.8,26.8.28.8,26.7.32.4,26.3.52.8