Repository navigation
fix(frontend): reject syntax nested too deep instead of crashing the scan (#233) - #234
Merged
Merged
Conversation
…n on Python 3.11 (#233)
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.
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) raisedRecursionError, which aborted the whole scan with no report. The frontend now checks, without recursion, that no syntax is nested more thanMAX_NESTING(500) levels before building PyHIR, and otherwise raisesHIRBuildErrornaming the place: the file is reported as asyntax-errornote withsyntax-errorcoverage, 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 withRecursionErrorbefore 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 localtest_packagingenvironment 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