Skip to content

re: undocumented exception is raised #109747

Closed

Description

@fuzzah

Bug report

Bug description:

The re module's documentation says it only raises the re.error exception, but the regex "\x00(?<!\x00{2147483648})" causes RuntimeError:

Python 3.11.5 (main, Sep 20 2023, 10:46:56) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> re.compile("\x00(?<!\x00{2147483647})")
re.compile('\x00(?<!\x00{2147483647})')
>>>
>>>
>>> re.compile("\x00(?<!\x00{2147483648})")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.11/re/__init__.py", line 227, in compile
    return _compile(pattern, flags)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/re/__init__.py", line 294, in _compile
    p = _compiler.compile(pattern, flags)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/re/_compiler.py", line 759, in compile
    return _sre.compile(
           ^^^^^^^^^^^^^
RuntimeError: invalid SRE code

Other re methods, such as match or split show the same result.

For brevity:
"\x00(?<!\x00{2147483648})" -> RuntimeError
"\x00(?<!\x00{2147483647})" -> no errors

I have found this with libFuzzer by testing the fuzz_sre_compile binary.

CPython versions tested on:

3.11

Operating systems tested on:

Linux

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Sep 22, 2023
  2. AA-Turner commented on Sep 22, 2023

    @AA-Turner
    Member
  3. AA-Turner commented on Sep 22, 2023

    @AA-Turner
    Member

    @fuzzah are you able to reproduce the error with 3.12.0rc3 or 3.13.0a0?

    A

  4. fuzzah commented on Sep 22, 2023

    @fuzzah
    Author

    @AA-Turner , for both versions the answer is yes.

    My checked out commit of 3.13.0a0 is this:

    commit 7c553991724d8d537f8444db73f016008753d77a (grafted, HEAD -> main, origin/main, origin/HEAD)
    Author: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
    Date:   Fri Sep 22 17:59:35 2023 +0100
    
        gh-109719: Fix missing jump target labels when compiler reorders cold/warm blocks (#109734)
    
  5. added
    3.11only security fixes
    3.12only security fixes
    3.13only security fixes
    on Sep 22, 2023
  6. fuzzah commented on Sep 22, 2023

    @fuzzah
    Author

    Might be related: #91700, #98740

  7. serhiy-storchaka commented on Sep 22, 2023

    @serhiy-storchaka
    Member

    Confirm the bug. The RE engine has limitation on the width of look-behind pattern. But there were no checks for this or they did not work. I will see how it can be fixed.

  8. added a commit that references this issue on Sep 25, 2023
  9. added a commit that references this issue on Oct 14, 2023
  10. added 2 commits that reference this issue on Oct 14, 2023
  11. added 2 commits that reference this issue on Oct 14, 2023
  12. serhiy-storchaka commented on Oct 14, 2023

    @serhiy-storchaka
    Member

    Now you will get better error message. Also, the limit is increased.

  13. added a commit that references this issue on Feb 11, 2024
  14. added a commit that references this issue on Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

3.11only security fixes3.12only security fixes3.13only security fixesdocsDocumentation in the Doc dirtopic-regextype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions