gh-120384: Fix array-out-of-bounds crash in list_ass_subscript (#120442)

This commit is contained in:
Nikita Sobolev 2024-06-21 13:48:38 +03:00 committed by GitHub
parent 733dac01b0
commit 8334a1b55c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 58 additions and 12 deletions

View file

@ -245,6 +245,20 @@ class ListTest(list_tests.CommonTest):
with self.assertRaises(TypeError):
a[0] < a
def test_list_index_modifing_operand(self):
# See gh-120384
class evil:
def __init__(self, lst):
self.lst = lst
def __iter__(self):
yield from self.lst
self.lst.clear()
lst = list(range(5))
operand = evil(lst)
with self.assertRaises(ValueError):
lst[::-1] = operand
@cpython_only
def test_preallocation(self):
iterable = [0] * 10