diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2023-10-14 09:13:02 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-14 09:13:02 +0300 |
commit | e2b3d831fd2824d8a5713e3ed2a64aad0fb6b62d (patch) | |
tree | 3ab33a7a92325e48c5297ba9c3f4d8d9c38d3d00 /Lib/re/_compiler.py | |
parent | ca0f3d858d069231ce7c5b382790a774f385b467 (diff) | |
download | cpython-e2b3d831fd2824d8a5713e3ed2a64aad0fb6b62d.tar.gz cpython-e2b3d831fd2824d8a5713e3ed2a64aad0fb6b62d.zip |
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).
Diffstat (limited to 'Lib/re/_compiler.py')
-rw-r--r-- | Lib/re/_compiler.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/Lib/re/_compiler.py b/Lib/re/_compiler.py index d0a4c55caf6..f87712d6d6f 100644 --- a/Lib/re/_compiler.py +++ b/Lib/re/_compiler.py @@ -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 |