gh-106524: Zero template items before initializing them in _sre.template#106525
gh-106524: Zero template items before initializing them in _sre.template#106525serhiy-storchaka merged 4 commits intopython:mainfrom chgnrdv:sre-template-invalid-group-index
_sre.template#106525Conversation
* 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 <52372310+chgnrdv@users.noreply.github.com>
Fixes #106524
_sre_template_implset items of 'self->items' array to zero before initializing them with group indices and literals_sre.templatecrashes in case of negative or non-integer group index #106524