Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser compares int to Py_ssize_t poorly #120956

Closed
zooba opened this issue Jun 24, 2024 · 3 comments
Closed

Parser compares int to Py_ssize_t poorly #120956

zooba opened this issue Jun 24, 2024 · 3 comments
Assignees

Comments

@zooba
Copy link
Member

zooba commented Jun 24, 2024

I'm not sure how widespread this is, or how generated the code is, but within _loop0_139_rule in parser.c we find this:

    Py_ssize_t _n = 0;
    // some lines later
    for (int i = 0; i < _n; i++) asdl_seq_SET_UNTYPED(_seq, i, _children[i]);

If _n can never be larger than MAX_INT (likely), there seems no reason it can't be int. Alternatively, if i has to increment all the way up to _n, it should be Py_ssize_t.

Otherwise, an infinite loop is theoretically possible, and clever static analysers will take great pride in reminding us about this possibility until we fix it.

(I'd jump in and fix this myself but I've never touched this code before and am not sure where to start. Should be easy enough for someone who does know, though.)

Linked PRs

@lysnikolaou
Copy link
Contributor

Opened #120959.

@mdboom
Copy link
Contributor

mdboom commented Jun 24, 2024

clever static analysers will take great pride in reminding us about this possibility until we fix it.

Was there a specific clever static analyser that found this in this case?

@zooba
Copy link
Member Author

zooba commented Jun 24, 2024

Was there a specific clever static analyser that found this in this case?

CodeQL, though running on a different copy of the repo than this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants