Files
turso/sqlite/parser
roboturso 8011555c64 sqlite/parser: bound expression depth to prevent translator stack overflow
Deeply nested or very wide expression trees could reach the recursive
translator/optimizer and overflow the native stack (issue #5071).

Add a fixed expression-depth limit in the parser, our equivalent of
SQLite's SQLITE_MAX_EXPR_DEPTH but lower, since our translator uses larger
stack frames per nesting level. The limit is enforced in two places while
the AST is built, so over-deep input fails deterministically with a parse
error before any recursive pass sees it:

- parse_expr bounds the parser's own recursion depth, catching deeply
  nested shapes (CASE, subqueries, parenthesized terms) during parsing;
- last_expr_height tracks expression height bottom-up (1 + max child
  height, like SQLite's Expr.nHeight) and is checked against the limit,
  catching wide left-deep chains such as 1 OR 1 OR ... that the parser
  consumes iteratively.

The height check runs up front on each operand (so an operand that is
already over the limit and not followed by an operator is still rejected),
and function-call height folds in the ORDER BY / WITHIN GROUP / FILTER /
OVER clauses (including FunctionCallStar), since later passes walk
expressions inside those clauses too.

Add an in-process regression test that generates each recursion vector
(OR/AND/arithmetic chains, nested parens, CASE, scalar subquery, function
nesting, FILTER and window clauses) from the limit constant, runs it on a
thread with a controlled stack, and asserts the exact error at the limit
while parsing cleanly one below it. Add a Turso-only conformance test
generated from the limit, and bound the clique-join fuzz test to sizes
whose WHERE predicate stays within the limit.

Fixes #5071
2026-07-02 12:14:11 +03:00
..

TODO