mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-97616: list_resize() checks for integer overflow (GH-97617)
Fix multiplying a list by an integer (list *= int): detect the
integer overflow when the new allocated length is close to the
maximum size. Issue reported by Jordan Limor.
list_resize() now checks for integer overflow before multiplying the
new allocated length by the list item size (sizeof(PyObject*)).
(cherry picked from commit a5f092f3c4)
Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
parent
3d8dfb339b
commit
28f1435d94
3 changed files with 24 additions and 2 deletions
|
|
@ -68,6 +68,19 @@ def imul(a, b): a *= b
|
|||
self.assertRaises((MemoryError, OverflowError), mul, lst, n)
|
||||
self.assertRaises((MemoryError, OverflowError), imul, lst, n)
|
||||
|
||||
def test_list_resize_overflow(self):
|
||||
# gh-97616: test new_allocated * sizeof(PyObject*) overflow
|
||||
# check in list_resize()
|
||||
lst = [0] * 65
|
||||
del lst[1:]
|
||||
self.assertEqual(len(lst), 1)
|
||||
|
||||
size = ((2 ** (tuple.__itemsize__ * 8) - 1) // 2)
|
||||
with self.assertRaises((MemoryError, OverflowError)):
|
||||
lst * size
|
||||
with self.assertRaises((MemoryError, OverflowError)):
|
||||
lst *= size
|
||||
|
||||
def test_repr_large(self):
|
||||
# Check the repr of large list objects
|
||||
def check(n):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue