Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-101955: Fix SystemError in possesive quantifier with alternative and group#111362
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
gh-101955: Fix SystemError in possesive quantifier with alternative and group#111362
Uh oh!
There was an error while loading.Please reload this page.
Conversation
serhiy-storchaka commentedOct 26, 2023
@animalize Could you please make a review of this PR? |
wjssz commentedOct 16, 2024
How about this patch? It's simpler: Modules/_sre/sre_lib.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)diff --git a/Modules/_sre/sre_lib.h b/Modules/_sre/sre_lib.hindex 97fbb0a75e5..2d124ab5ac3 100644--- a/Modules/_sre/sre_lib.h+++ b/Modules/_sre/sre_lib.h@@ -1294,6 +1294,18 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel) pointer */ state->ptr = ptr;+ /* Set state->repeat to non-NULL */+ ctx->u.rep = (SRE_REPEAT*) PyObject_Malloc(sizeof(*ctx->u.rep));+ if (!ctx->u.rep) {+ PyErr_NoMemory();+ RETURN_ERROR(SRE_ERROR_MEMORY);+ }+ ctx->u.rep->count = -1;+ ctx->u.rep->pattern = NULL;+ ctx->u.rep->last_ptr = NULL;+ ctx->u.rep->prev = state->repeat;+ state->repeat = ctx->u.rep;+ /* Initialize Count to 0 */ ctx->count = 0;@@ -1308,6 +1320,10 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel) } else { state->ptr = ptr;+ /* Restore state->repeat */+ state->repeat = ctx->u.rep->prev;+ PyObject_Free(ctx->u.rep);+ RETURN_FAILURE; } }@@ -1380,6 +1396,10 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel) } }+ /* Restore state->repeat */+ state->repeat = ctx->u.rep->prev;+ PyObject_Free(ctx->u.rep);+ /* Evaluate Tail */ /* Jump to end of pattern indicated by skip, and then skip the SUCCESS op code that follows it. */ |
serhiy-storchaka commentedNov 14, 2024
@wjssz, would not it leak memory in case of error (when user interrupted evaluation by pressing Ctrl-C)? There are two differences of this PR from your patch:
But I have suspect that it does not work. It is difficult to test the former case, and the latter case may work incorrectly in case of nested possessive repetitions. So it may be safer to use your simpler patch and fix memory leaks later. Do you mind to create a PR@wjssz? |
wjssz commentedNov 14, 2024
I'm@animalize, this is my new GitHub account.
You are right. Maybe
Sorry. I'm not going to sign CLA.
I have a patch for this. I'll post it after. |
serhiy-storchaka commentedNov 14, 2024
You are welcome @wjssz/@animalize. It was pleasure to work with you last time. Right now I'm writing a code which would help to test user interruption and catch memory leaks. |
Co-authored-by: <wjssz@users.noreply.github.com>
serhiy-storchaka commentedNov 18, 2024
Now, after fixing leaks and using memory pool for SRE_REPEAT, the simpler patch#111362 (comment) can be used. Thanks@wjssz. |
f9c5573 intopython:mainUh oh!
There was an error while loading.Please reload this page.
Thanks@serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. |
…tive and group (pythonGH-111362)(cherry picked from commitf9c5573)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>Co-authored-by: <wjssz@users.noreply.github.com>
GH-126962 is a backport of this pull request to the3.13 branch. |
…tive and group (pythonGH-111362)(cherry picked from commitf9c5573)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>Co-authored-by: <wjssz@users.noreply.github.com>
GH-126963 is a backport of this pull request to the3.12 branch. |
…tive and group (pythonGH-111362)Co-authored-by: <wjssz@users.noreply.github.com>
Uh oh!
There was an error while loading.Please reload this page.