Crash when using multiple capturing groups in re.Scanner (original) (raw)
Bug report
Bug description:
The re.Scanner class crashes with a segmentation fault (memory corruption) when any pattern in the lexicon contains named capturing groups.
import re
lexicon = [ ('(?Pa)(?Pb)', None), # Named capturing groups ]
scanner = re.Scanner(lexicon) result, leftover = scanner.scan("ab") # Segmentation fault occurs here
zsh: segmentation fault python3 test.py
Scanner should process the input normally and return scan results without crashing, but Python interpreter crashes with segmentation fault, indicating memory corruption.
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
- gh-140797: Forbid capturing groups in re.Scanner lexicon patterns #140944
- [3.14] gh-140797: Forbid capturing groups in re.Scanner lexicon patterns (GH-140944) #140982
- [3.13] gh-140797: Forbid capturing groups in re.Scanner lexicon patterns (GH-140944) #140983
- gh-140979: Fix off-by-one error in the RE code validator #140984
- [3.13] Revert "[3.13] gh-140797: Forbid capturing groups in re.Scanner lexicon patterns (GH-140944) (GH-140983)" #142231
- [3.14] Revert "gh-140797: Forbid capturing groups in re.Scanner lexicon patterns (GH-140944) (GH-140982)" #142309