go-python / gpython

gpython is a python interpreter written in go "batteries not included"
BSD 3-Clause "New" or "Revised" License
870 stars 95 forks source link

Slicing large list causes segfault of gpython #197

Closed xiaxinmeng closed 1 year ago

xiaxinmeng commented 1 year ago

The following code takes a slice of a large list and then gpython crashes with a segmentation fault. The same test code can work well on CPython 3.9.0 and print a result "[1, 3]".

test.py

class X:
    def __index__(self):
        b[:] = [1, 2, 3]
        return 2
b = [123] * 4096
print(b[0:64:X()])

Environment: gpython 0.1.0 on Ubuntu 18.04, and gpython main(6f8e06a4660709ab44398d8b1a18738aa407b1c3 on Oct 5)

ncw commented 1 year ago

This doesn't work, but it doesn't crash

$ cat > issue-197.py
class X:
    def __index__(self):
        b[:] = [1, 2, 3]
        return 2
b = [123] * 4096
print(b[0:64:X()])

$ gpython issue-197.py
Traceback (most recent call last):
  File "issue-197.py", line 6, in <module>
    FIXME line of source goes here
TypeError: "unsupported operand type(s) for index: 'X'"
2022/12/05 08:56:39 TypeError: "unsupported operand type(s) for index: 'X'"

vs

$ python3 issue-197.py
[1, 3]