diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2022-11-03 07:23:46 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-03 07:23:46 (GMT) |
commit | e9ac890c0273aee413aa528cc202c3efa29f1d7a (patch) | |
tree | e9dc563c58e25de5dd3f5b592fa5575ea486349d /Lib/test/test_re.py | |
parent | 41bc101dd6726edc5fbd4a934ea057ec712d5498 (diff) | |
download | cpython-e9ac890c0273aee413aa528cc202c3efa29f1d7a.zip cpython-e9ac890c0273aee413aa528cc202c3efa29f1d7a.tar.gz cpython-e9ac890c0273aee413aa528cc202c3efa29f1d7a.tar.bz2 |
gh-98740: Fix validation of conditional expressions in RE (GH-98764)
In very rare circumstances the JUMP opcode could be confused with the
argument of the opcode in the "then" part which doesn't end with the
JUMP opcode. This led to incorrect detection of the final JUMP opcode
and incorrect calculation of the size of the subexpression.
NOTE: Changed return value of functions _validate_inner() and
_validate_charset() in Modules/_sre/sre.c. Now they return 0 on success,
-1 on failure, and 1 if the last op is JUMP (which usually is a failure).
Previously they returned 1 on success and 0 on failure.
Diffstat (limited to 'Lib/test/test_re.py')
-rw-r--r-- | Lib/test/test_re.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index 3f0f84e..11628a2 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -630,6 +630,11 @@ class ReTests(unittest.TestCase): self.checkPatternError(r'()(?(2)a)', "invalid group reference 2", 5) + def test_re_groupref_exists_validation_bug(self): + for i in range(256): + with self.subTest(code=i): + re.compile(r'()(?(1)\x%02x?)' % i) + def test_re_groupref_overflow(self): from re._constants import MAXGROUPS self.checkTemplateError('()', r'\g<%s>' % MAXGROUPS, 'xx', |