gh-112625: Protect bytearray from being freed by misbehaving iterator inside bytearray.join (GH-112626)

This commit is contained in:
chilaxan 2023-12-04 03:15:43 -05:00 committed by GitHub
parent 23e001fa9f
commit 0e732d0997
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 1 deletions

View file

@ -2039,6 +2039,23 @@ class BuiltinTest(unittest.TestCase):
bad_iter = map(int, "X")
self.assertRaises(ValueError, array.extend, bad_iter)
def test_bytearray_join_with_misbehaving_iterator(self):
# Issue #112625
array = bytearray(b',')
def iterator():
array.clear()
yield b'A'
yield b'B'
self.assertRaises(BufferError, array.join, iterator())
def test_bytearray_join_with_custom_iterator(self):
# Issue #112625
array = bytearray(b',')
def iterator():
yield b'A'
yield b'B'
self.assertEqual(bytearray(b'A,B'), array.join(iterator()))
def test_construct_singletons(self):
for const in None, Ellipsis, NotImplemented:
tp = type(const)