Repository navigation
Conversation
TypeParser::Parse() calls top() and pop() on its element stack for every ')' and ',', so a type name with a surplus closing parenthesis such as "UInt8))" or ")," reads from an empty std::stack and crashes. It also has no nesting limit, while CreateColumnFromAst() and the TypeAst destructor recurse once per level, so a type nested 100000 levels deep, closed or not, overflows the stack. Parse() now fails on a ')' or ',' with no open parenthesis and on nesting deeper than 512 levels: current servers reject column types nested deeper than 499 levels, and 512 keeps the recursive paths to about 250 KiB of stack in an optimized build.
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.
Two server-supplied type strings crash
CreateColumnByType.A surplus
)or,makesTypeParser::Parse()intypes/type_parser.cppcallopen_elements_.top()andpop()on an emptystd::stack, which is undefined behaviour on an empty deque. Release builds segfault onUInt8)),),or))).Deep nesting overflows the stack.
CreateColumnFromAstincolumns/factory.cpprecurses once per nesting level, and so does theTypeAstdestructor. A type string of about 700 KB (Array(repeated 100,000 times) overflows the stack whether or not it is closed.Fix:
Parse()returns false on a)or,with no open element, and on nesting deeper thanTypeParser::kMaxNestingDepth(512). That bounds both the factory recursion and AST destruction. Current servers reject column types nested deeper than 499 levels (26.9 accepts at most 497 nestedArray(levels at default settings, 499 with the AST limits raised), so 512 rejects nothing a server can produce. It also keeps the worst-case stack near 250 KiB in an optimized build. A side effect: top-level commas (UInt8, String) andUInt8)(are now rejected; neither is a valid type.Reproducer type strings:
UInt8)),),,))), andArray(× 100000 followed byUInt8(closed or unclosed).Tests in
ut/type_parser_ut.cpp:UnbalancedClosingParenthesiscovers 13 malformed strings.NestingDepthLimitaccepts depth 512 and rejects 513 and 100000, closed and unclosed.NestingDepthLimitBoundsColumnFactorychecks that a 499-level type still builds a column and deeper types return nullptr.BalancedNestedControlscoversMap(String, Array(Nullable(UInt8))),Tuple(a UInt8, b String)and deepArray.The first three crash on master; the controls pass on both.