Skip to content

fix(frontend): reject syntax nested too deep instead of crashing the scan (#233) - #234

Merged
SizzleUnrlsd merged 2 commits into
mainfrom
fix/deep-nesting
Oct 8, 2026
Merged

SizzleUnrlsd merged 2 commits into
mainfrom
fix/deep-nesting

Conversation

@SizzleUnrlsd

Copy link
Copy Markdown
Contributor

Summary

Python parses left-nested chains of any length ("a" + "b" + …, a.b.b…, x.strip().strip()…); the frontend converts them recursively, one frame per level, and past about 985 levels of AST nesting (about 500 chained calls) raised RecursionError, which aborted the whole scan with no report. The frontend now checks, without recursion, that no syntax is nested more than MAX_NESTING (500) levels before building PyHIR, and otherwise raises HIRBuildError naming the place: the file is reported as a syntax-error note with syntax-error coverage, as any file the frontend cannot represent, and the rest of the project is analysed. The bound does not depend on the call stack and leaves the later recursive stages room (they handle about 900 levels).

Verification

New tests in tests/test_deep_nesting.py (red with RecursionError before the fix): three deep files rejected while another file's finding is still reported, the rejection's location, and syntax within the bound analysed. Full suite green apart from the local test_packaging environment issue; ruff, mypy clean; regression snapshots and the mitmproxy scan (75 findings) unchanged; the check takes 0.66 s over mitmproxy's 583 files.

Closes #233

@SizzleUnrlsd SizzleUnrlsd added the bug Something isn't working label Oct 7, 2026
@SizzleUnrlsd SizzleUnrlsd self-assigned this Oct 7, 2026
@SizzleUnrlsd
SizzleUnrlsd merged commit 0e0db91 into main Oct 8, 2026
10 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.

frontend: a deeply nested expression crashes the whole scan with RecursionError

1 participant