Segmentation fault with recursive matches and atomic groups

Create issue
Issue #211 resolved
Former user created an issue

Duplicate of (resolved) #154?

  • regex==2016.5.23
  • Python 3.5.1+ (default, May 9 2016, 11:00:17) [GCC 5.3.1 20160429] on linux
  • Linux _ 4.5.0-2-amd64 #1 SMP Debian 4.5.4-1 (2016-05-16) x86_64 GNU/Linux

Steps to reproduce:

from regex import compile, VERBOSE, VERSION1

r = compile(r'''
    \A(?P<whole>
        (?>
            \( (?&whole) \)
            |
            (?>
                (?> (?P<minus> -) | [+] )
            )
        )
    )\Z
''', VERBOSE | VERSION1)

r.match('((-))')   # <regex.Match object; span=(0, 5), match='((-))'>
r.match('((-)+)')  # segmentation fault

Backtrace:

Program received signal SIGSEGV, Segmentation fault.
pop_group_return (state=state@entry=0x7fffffffc230) at Python3/_regex.c:3092
3092    Python3/_regex.c: Datei oder Verzeichnis nicht gefunden.
(gdb) bt
#0  pop_group_return (state=state@entry=0x7fffffffc230) at Python3/_regex.c:3092
#1  0x00007ffff5ea2800 in basic_match (safe_state=safe_state@entry=0x7fffffffc1c0, search=<optimized out>, search@entry=0 '\000') at Python3/_regex.c:14681
#2  0x00007ffff5eaaf63 in do_exact_match (search=<optimized out>, safe_state=<optimized out>) at Python3/_regex.c:16920
#3  do_match (safe_state=safe_state@entry=0x7fffffffc1c0, search=search@entry=0 '\000') at Python3/_regex.c:16959
#4  0x00007ffff5eada5d in pattern_search_or_match (self=0x7ffff621a178, args=<optimized out>, kwargs=<optimized out>, args_desc=<optimized out>, 
    search=<optimized out>, match_all=<optimized out>) at Python3/_regex.c:20188
#5  0x00000000004e6027 in PyCFunction_Call ()
#6  0x0000000000532f2f in PyEval_EvalFrameEx ()
#7  0x000000000053bdb9 in ?? ()
#8  0x000000000053ca9f in PyEval_EvalCode ()
#9  0x0000000000616e82 in ?? ()
#10 0x000000000049b381 in PyRun_InteractiveOneObject ()
#11 0x000000000049b52a in PyRun_InteractiveLoopFlags ()
#12 0x000000000049c9a5 in ?? ()
#13 0x00000000004d1915 in ?? ()
#14 0x00000000004d2451 in main ()

Comments (3)

  1. Former user Account Deleted

    Adding

    if (!frame) {
        return NULL;
    }
    

    in _regex.c after

    frame = state->current_group_call_frame;
    

    removes the segmentation fault, but I cannot say if this fix is sane.

    Valgrind prints many screen pages of warnings for cpython before you even see a prompt, so debugging seems kinda futile to me.

  2. Log in to comment