-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-106524: Zero template items before initializing them in _sre.template
#106525
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-106524: Zero template items before initializing them in _sre.template
#106525
Conversation
* made `_sre_template_impl` set items of 'self->items' array to zero before initializing them with group indices and literals * added test
Good catch. Other approach is to call |
@serhiy-storchaka, benchmarks speak for themselves:
main: with memset: with Py_SET_SIZE: |
Thanks @chgnrdv for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11. |
Thanks @chgnrdv for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. |
Sorry @chgnrdv and @serhiy-storchaka, I had trouble checking out the |
GH-106544 is a backport of this pull request to the 3.12 branch. |
Some items remained uninitialized if _sre.template() was called with invalid indices. Then attempt to clear them in the destructor led to dereferencing of uninitialized pointer. (cherry picked from commit 2ef1dc3) Co-authored-by: Radislav Chugunov <[email protected]>
Fixes #106524
_sre_template_impl
set items of 'self->items' array to zero before initializing them with group indices and literals_sre.template
crashes in case of negative or non-integer group index #106524