0

I have a Python-powered DSL which I execute through exec(). This DSL includes a native function calls through CFFI.

I'm getting stack overflow (SO, you made it ungooglable!) crash when calling a native function which is just 2 C calls deep, with only a handful of uint16_ts allocated on a stack in each C function. Python application is a tkinter GUI that calls the DSL by timer (master.after(1000, self.tick)) event, which might take a good portion of stack itself.

There are NO recursive calls here.

OS X 10.12.3, Python 3.6.0rc1 (v3.6.0rc1:29a273eee9a5, Dec 6 2016, 16:24:13), CFFI 1.9.1

I'm aware of resource.setrlimit(resource.RLIMIT_STACK, (resource.RLIM_INFINITY, resource.RLIM_INFINITY)), but it requires a superuser privilege. I believe this is not needed, as it's not normal to only have a stack remaining for two function calls.

Could CFFI or exec() be limiting the stack size for the callee?

Function being called from DSL:

ffi_builder.cdef('''
//...
int FooNode_SetProperty(struct FooNode *pThis, const char *szPropertyName, int nValue);
''')

def set_channel(node, channel):
    node.SetProperty(b'channel', channel)

exec invocation code:

    self._globals = {
        '__builtins__': __builtins__,  
        # https://docs.python.org/3/library/functions.html#eval "If the globals dictionary is present and lacks
        # ‘__builtins__’, the current globals are copied into globals before expression is parsed."

        'run': {
            'duration': 60 * MICROS,
            'success': None
        },

        'set_channel': set_channel,
        'turn_off': turn_off,
        'turn_on': turn_on,
        'finish': finish,
        # 6 more functions here
    }

    exec(event_text, self._globals, {})

Apple report piece:

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Application Specific Information:
[35633] stack overflow

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib          0x00000001003bfdd6 __pthread_kill + 10
1   libsystem_pthread.dylib         0x00007fffe03dc787 pthread_kill + 90
2   libsystem_c.dylib               0x00007fffe02564bb __abort + 140
3   libsystem_c.dylib               0x00007fffe0256d7e __stack_chk_fail + 205
4   libmush_real.dylib          0x0000000104c4d714 send_counters_report_request + 532

(this thread really ends here, nothing else in Apple report)

Victor Sergienko
  • 13,115
  • 3
  • 57
  • 91

1 Answers1

0

Managed to connect with a debugger.

The stack that has nothing after the current call is a sign that a stack was overwritten, normally via a pointer to a stack variable.

Victor Sergienko
  • 13,115
  • 3
  • 57
  • 91