diff options
author | chilaxan <chilaxan@gmail.com> | 2023-12-04 08:15:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-04 08:15:43 (GMT) |
commit | 0e732d0997cff08855d98c17af4dd5527f10e419 (patch) | |
tree | bcd591f1f0b461af4b45ad220454520a14a4278f /Lib/test/test_builtin.py | |
parent | 23e001fa9f1897ba3384c02bbbe634313358a549 (diff) | |
download | cpython-0e732d0997cff08855d98c17af4dd5527f10e419.zip cpython-0e732d0997cff08855d98c17af4dd5527f10e419.tar.gz cpython-0e732d0997cff08855d98c17af4dd5527f10e419.tar.bz2 |
gh-112625: Protect bytearray from being freed by misbehaving iterator inside bytearray.join (GH-112626)
Diffstat (limited to 'Lib/test/test_builtin.py')
-rw-r--r-- | Lib/test/test_builtin.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index b7966f8..535856a 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -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) |