Repository navigation
fix(query): refuse statements too deep for the parser's stack - #128
Merged
Merged
Conversation
A statement nested below the 256-level limit could still run the parser out of stack on a JVM with smaller frames to spare. CI on Linux hit this with 10,000 brackets and SecurityTest got a StackOverflowError instead of an invalid-statement error. The parser now turns a stack overflow into that error.
A chain like 1+1+...+1 parses into a left-deep tree that the evaluator walks recursively, and arguments of nested calls were parsed without going through the nesting counter. Both could still exhaust the stack: 5,000 terms were enough to kill a server connection without a reply. Each extra link of an arithmetic chain and each call argument now counts towards the 256-level limit.
This was referenced Nov 24, 2026
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.
CI has failed on every merge to main since 23 November, always on
SecurityTest.extremeInputsFailCleanly. On the Linux runner (GraalVM CE 25.0.2), the statement with 10,000 nested brackets threw aStackOverflowErrorinstead of the expected invalid-statement error. The parser stops at 256 levels of nesting, but each level takes about ten frames, and that runner ran out of stack before reaching the limit. It passed on macOS, which is why local builds never showed it.Two changes:
statement is nested too deeply to parse. Nothing is left half-done because all parser state lives on the parser instance, which is thrown away.1+1+…+1parses into a left-deep tree that the evaluator walks recursively, and nested call arguments skipped the counter. With 5,000 terms the evaluator ran out of stack on the server and the connection closed without a reply. Now the parser refuses the statement.ParserDepthTestcovers:NOTs on a 64 KB stack either parse or are refused, and never throwStackOverflowError. Before the fix this test failed with the sameStackOverflowErroras CI.+or*terms, 300 nestedabs(calls, and brackets mixed with a chain are refused.Removing either of the two new counts makes the test fail.
Full build: engine 269, database 293, server 41, no failures.
Merge order for the memory stack: #128 (CI fix), #124, #125, #126, #127, #129 (online text index rebuild), #130 (starter kit). Retarget each to main once the one below it merges. A private preview image built from #129 merged with #128 is at ghcr.io/metacoglabs/hstore-memory:0.2.0-dec80f2.