gh-109747: Improve errors for unsupported look-behind patterns (GH-109859)

Now re.error is raised instead of OverflowError or RuntimeError for
too large width of look-behind pattern.

The limit is increased to 2**32-1 (was 2**31-1).
This commit is contained in:
Serhiy Storchaka 2023-10-14 09:13:02 +03:00 committed by GitHub
parent ca0f3d858d
commit e2b3d831fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 46 additions and 13 deletions

View file

@ -147,6 +147,8 @@ def _compile(code, pattern, flags):
emit(0) # look ahead
else:
lo, hi = av[1].getwidth()
if lo > MAXCODE:
raise error("looks too much behind")
if lo != hi:
raise error("look-behind requires fixed-width pattern")
emit(lo) # look behind
@ -547,7 +549,7 @@ def _compile_info(code, pattern, flags):
else:
emit(MAXCODE)
prefix = prefix[:MAXCODE]
emit(min(hi, MAXCODE))
emit(hi)
# add literal prefix
if prefix:
emit(len(prefix)) # length