Repository navigation
Conversation
The compiler recurses once per type-expression suffix (`Int32.a.a...`, `Int32()()...`) and once per link of a chain of declarations that refer to each other (aliases, constants, annotations, struct field types, superclasses, imports). A long flat chain therefore exhausts the thread stack, and no lexical bound on the schema text can see those chains. Add `setStackCheck()`, a process-wide hook (unset by default, so behaviour is unchanged) that the compiler runs at the top of `BrandScope::compileDeclExpression` and of `Compiler::Node::traverse`. The first bounds every chain whose links are compiled by name; the second bounds the eager dependency traversal, which can walk links that were already compiled elsewhere (for example the types of struct default values). If the hook throws, compilation fails with an OVERLOADED "Schema is nested too deeply." exception. `resolveBootstrapType` rethrows OVERLOADED unchanged: the lazy bootstrap load it guards can re-enter the compiler, and wrapping the error at every level would turn it into a quadratic "Internal compiler bug" message. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Member
|
Using https://github.com/ClickHouse/capnproto/tree/ClickHouse/v1.5.0 instead of master (updated the branch, cherry-picked the commits there) |
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.
The schema compiler recurses once per type-expression suffix (
Int32.a.a...,Int32()()...), once per link of a chain of declarations that refer to each other by name (aliases, constants, annotations, struct field types, superclasses, imports), and once per level of the eager dependency traversal. A long flat chain exhausts the thread stack: in ClickHouse oneDESC format(CapnProto, '')with such a schema kills the server with SIGSEGV (ClickHouse/ClickHouse#125782). ClickHouse's existing check bounds only the bracket nesting of the text, and these chains are only visible after name resolution.This adds
capnp::compiler::setStackCheck(void (*)()), a process-wide hook that is unset by default, so behaviour without it is unchanged. The compiler runs it at two places:BrandScope::compileDeclExpression, which bounds every chain whose next link is compiled by name;Compiler::Node::traverse, which bounds the eager dependency traversal. It can walk links that were already compiled elsewhere without compiling any name (for example the types of struct default values, compiled to bootstrap from the defining struct), so the first check alone does not see that depth.When the hook throws, compilation fails with an OVERLOADED "Schema is nested too deeply." exception; the hook's own exception never travels through capnp frames.
resolveBootstrapTyperethrows OVERLOADED unchanged: the lazy bootstrap load it guards can re-enter the compiler, and wrapping the error at every level would turn it into a quadratic "Internal compiler bug" message.ClickHouse installs its
checkStackSizeas the hook: ClickHouse/ClickHouse#125900.🤖 Generated with Claude Code