-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-103656: Transfer f-string buffers to parser to avoid use-after-free #103896
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
gh-103656: Transfer f-string buffers to parser to avoid use-after-free #103896
Conversation
After off-line discussions with @pablogsal, we felt that the best way forward is to add metadata to tokens and use it to pass the fstring debug buffer from the tokenizer to the parser, store it in the arena and ensure that its lifetime is okay for us to use in later passes as well. cc @sunmy2019 whose review I can't request. |
Parser/tokenizer.c
Outdated
@@ -432,6 +433,15 @@ update_fstring_expr(struct tok_state *tok, char cur) | |||
case ':': | |||
if (tok_mode->last_expr_end == -1) { | |||
tok_mode->last_expr_end = strlen(tok->start); | |||
PyObject *res = PyUnicode_DecodeUTF8( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hummm, not sure if this is the place where we should be doing this. Isn't it better to set the metadata when we create the token itself? This way we don't need to pass down the token all the way to here. This function just updates the pointers and at the point when we have the token ready we set the metadata (because the pointers are ready).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me push a commit to see what I mean
02ab63e
to
4cbd070
Compare
4cbd070
to
51d7d83
Compare
… avoid use-after-free
This is leaking refs in its current state. My guess is that we are not cleaning the python objects for f-strings that don't get debug info. |
5920b9f
to
326059e
Compare
…rser to avoid use-after-free
Btw as an optimization we should only set the metadata if the f-string has a '=' |
…s to parser to avoid use-after-free
Found the refleaks, the only thing missing is to fix #103896 (comment) |
I can take that. |
I just did it 😉 |
Although I may have messed something in Windows? |
Thanks for the help on this @pablogsal. All changes look good. |
Looks great! |
closes: #103656