ironpython3 icon indicating copy to clipboard operation
ironpython3 copied to clipboard

Incorrect argument in function select() causes stack overflow

Open xiaxinmeng opened this issue 3 years ago • 3 comments

This piece of code leads to a stack overflow. The execution of the program stops at stacktrace. See the following reporting information. I think the problem may be related to recursion, the code basically ends up with an unlimited number of iterations of select.select and test_select_mutated on the call stack and this doesn't trigger the stack depth checker.

test.py

import select

def test_select_mutated():
    a = []
    class F:
        def fileno(a):
            del test_select_mutated()[-1]
            return sys.__stdout__.fileno()
    a[:] = [F()] * 10
    select.select([], a, []), ([], a[:5], [])


test_select_mutated()

Environmental:

IronPython 3.4.0a1 (3.4.0.0001)
[.NETFramework,Version=v4.6 on Mono 6.12.0.122 (tarball Mon Feb 22 17:28:32 UTC 2021) (64-bit)] on linux

Error report:

(base) xxm@xxm-System-Product-Name:~$ ipy test.py
Stack overflow in unmanaged: IP: 0x718dd9, fault addr: 0x7ffcd96beff8
Stack overflow: IP: 0x7f734c953bce, fault addr: 0x7ffcd96b6fc8
Stacktrace:
at <unknown> <0xffffffff>

xiaxinmeng avatar Jul 26 '21 07:07 xiaxinmeng

This one also kills the CPython interpreter.

slozier avatar Jul 27 '21 02:07 slozier

Yes, I also reported it to CPython developers, They comment that this bug may be fixed by adding a stack depth check.

xiaxinmeng avatar Jul 27 '21 02:07 xiaxinmeng

CPython bug report: https://bugs.python.org/issue44718

slozier avatar Jul 29 '21 01:07 slozier