Skip to content

Grow the stack in the translator's recursion - #157

Merged
LucaCappelletti94 merged 2 commits into
mainfrom
fix/translator-stack-depth
Oct 26, 2026
Merged

LucaCappelletti94 merged 2 commits into
mainfrom
fix/translator-stack-depth

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Collaborator

A left-deep chain such as a + a + … + a aborted the process with a stack overflow, which no caller can catch, at 74 operands in a release build and 13 in a debug build on a 2 MiB thread. sqlparser reads such chains iteratively, so it accepts them at any length and hands over a tree the translator then walks recursively.

Every recursion cycle of the forward and reverse translators now carries #[recursive] under the std feature, the same guard sqlparser's recursive-protection uses. Statement translation also raises recursive's minimum headroom to 256 KiB, because one step of the expression translator takes about 140 KiB in a debug build. The same chains now translate past 1,800 operands in release and about 350 in debug. The remaining aborts happen in sqlparser's derived Clone and in sql-traits, and will be reported upstream.

@LucaCappelletti94 LucaCappelletti94 added the bug Something isn't working label Oct 24, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These duplicates are not on lines GitHub shows in this pull request diff, the inline comment cannot attach there. The links point at the copies on the head commit.

@codecov

codecov Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

A left-deep chain such as `a + a + … + a` aborted the process with a stack overflow, which no caller can catch, at 74 operands in a release build and 13 in a debug build on a 2 MiB thread. sqlparser reads such chains iteratively, so it accepts them at any length and hands over a tree the translator then walks recursively.

Every recursion cycle of the forward and reverse translators now carries `#[recursive]` under the `std` feature, the same guard sqlparser's `recursive-protection` uses. Statement translation also raises `recursive`'s minimum headroom to 256 KiB, because one step of the expression translator takes about 140 KiB in a debug build. The same chains now translate past 1,800 operands in release and about 350 in debug, and the remaining aborts happen in sqlparser's derived `Clone` and in sql-traits.
@LucaCappelletti94
LucaCappelletti94 force-pushed the fix/translator-stack-depth branch from 0affff8 to 481077e Compare October 25, 2026 22:06

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These duplicates are not on lines GitHub shows in this pull request diff, the inline comment cannot attach there. The links point at the copies on the head commit.

@LucaCappelletti94
LucaCappelletti94 merged commit 64f66ff into main Oct 26, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant