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

bpo-47256: re module, limit the maximum capturing group to 1,073,741,823, increasing the depth of backtracking. #32411

Merged
merged 5 commits into from Apr 18, 2022

Conversation

animalize
Copy link
Contributor

@animalize animalize commented Apr 8, 2022

Closes #91412.

@animalize
Copy link
Contributor Author

animalize commented Apr 12, 2022

I would like to remove the variable i in the SRE(match) function, just use a few variables with a smaller scope.
This change can be done in this PR or in a code polish PR.

Modules/_sre/sre.h Show resolved Hide resolved
Modules/_sre/sre.h Outdated Show resolved Hide resolved
@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Apr 15, 2022

I would like to remove the variable i in the SRE(match) function, just use a few variables with a smaller scope.

Do it.

animalize added 4 commits Apr 16, 2022
These types are kept as Py_ssize_t:
  - PatternObject.groups
  - MatchObject.lastindex
  - MatchObject.groups

- On 32 bit platform: 36 bytes, no change.  (msvc2022)
- On 64 bit platform: 72 bytes -> 64 bytes. (msvc2022/gcc9.4)
change the type of `SRE(match_context).jump` from Py_ssize_t to int

- On 32 bit platform: 36 bytes, no change.  (msvc2022)
- On 64 bit platform: 64 bytes -> 56 bytes. (msvc2022/gcc9.4)

And make the order of `DO_JUMPX` macro and `SRE(match_context)` struct consistent.
DATA_STACK_(PUSH|POP) macros use the size multiple time, now computed value is propagated.
@animalize
Copy link
Contributor Author

animalize commented Apr 16, 2022

Improved as your comments locally.
If you can find another review, I would like to update this PR.

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Apr 16, 2022

I have no other comments. Please update this PR.

@animalize
Copy link
Contributor Author

animalize commented Apr 16, 2022

I have no other comments. Please update this PR.

I mean reviewer...

Modules/_sre/sre_lib.h Outdated Show resolved Hide resolved
@serhiy-storchaka serhiy-storchaka merged commit a29f858 into python:main Apr 18, 2022
13 checks passed
@animalize animalize deleted the context_size branch Apr 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

re: limit the maximum capturing group to 1,073,741,823, reduce sizeof(match_context).
4 participants