Skip to content

Commit cf17abd

Browse files
committed
Add test for out-of-bounds read after resize
1 parent d5aa5c5 commit cf17abd

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_memoryview.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#
44
# Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
55

6+
import sys
7+
import pytest
68

79
def test_subscript():
810
v = memoryview(b'abcefg')
@@ -162,3 +164,21 @@ def test_pack():
162164
assert b == b'\x01'
163165
memoryview(b).cast('?')[0] = False
164166
assert b == b'\x00'
167+
168+
def test_read_after_resize():
169+
if sys.implementation.name != "graalpython":
170+
return
171+
# CPython prevents resizing of acquired buffers at all to avoid a segfault
172+
# We don't want to impose locking on managed objects because we cannot automatically
173+
# release the lock by reference counting. Check that we don't hard crash when
174+
# does an out-of-bound read on a resized buffer
175+
b = bytearray(b'12341251452134523463456435643')
176+
m = memoryview(b)
177+
assert m[1] == ord('2')
178+
b.clear()
179+
with pytest.raises(IndexError):
180+
print(m[1])
181+
with pytest.raises(IndexError):
182+
m[1] = 3
183+
with pytest.raises(IndexError):
184+
print(m.tobytes())

0 commit comments

Comments
 (0)