mirror of
https://github.com/python/cpython.git
synced 2025-08-27 04:05:34 +00:00
bpo-34973: Fix crash in bytes constructor. (GH-9841)
Constructing bytes from mutating list could cause a crash.
This commit is contained in:
parent
a323cdcb33
commit
914f9a078f
3 changed files with 88 additions and 35 deletions
|
@ -113,6 +113,23 @@ class BaseBytesTest:
|
|||
b = self.type2test([1, 2, 3])
|
||||
self.assertEqual(b, b"\x01\x02\x03")
|
||||
|
||||
def test_from_mutating_list(self):
|
||||
# Issue #34973: Crash in bytes constructor with mutating list.
|
||||
class X:
|
||||
def __index__(self):
|
||||
a.clear()
|
||||
return 42
|
||||
a = [X(), X()]
|
||||
self.assertEqual(bytes(a), b'*')
|
||||
|
||||
class Y:
|
||||
def __index__(self):
|
||||
if len(a) < 1000:
|
||||
a.append(self)
|
||||
return 42
|
||||
a = [Y()]
|
||||
self.assertEqual(bytes(a), b'*' * 1000) # should not crash
|
||||
|
||||
def test_from_index(self):
|
||||
b = self.type2test([Indexable(), Indexable(1), Indexable(254),
|
||||
Indexable(255)])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue