summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_bytes.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-06-29 18:13:54 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-06-29 18:13:54 (GMT)
commitab766350b665ff2cafb92191a7cd720a1ebf6fe7 (patch)
tree3aa9a213d1fc8433558ac2861b491337555024e5 /Lib/test/test_bytes.py
parenteabfe8cc0e061081d1cbcef4895a99cf7520e8d1 (diff)
downloadcpython-ab766350b665ff2cafb92191a7cd720a1ebf6fe7.zip
cpython-ab766350b665ff2cafb92191a7cd720a1ebf6fe7.tar.gz
cpython-ab766350b665ff2cafb92191a7cd720a1ebf6fe7.tar.bz2
Issue #24467: Fixed possible buffer over-read in bytearray. The bytearray
object now always allocates place for trailing null byte and it's buffer now is always null-terminated.
Diffstat (limited to 'Lib/test/test_bytes.py')
-rw-r--r--Lib/test/test_bytes.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index 988b931..02fba38 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -722,10 +722,27 @@ class ByteArrayTest(BaseBytesTest):
for i in range(100):
b += b"x"
alloc = b.__alloc__()
- self.assertTrue(alloc >= len(b))
+ self.assertGreater(alloc, len(b)) # including trailing null byte
if alloc not in seq:
seq.append(alloc)
+ def test_init_alloc(self):
+ b = bytearray()
+ def g():
+ for i in range(1, 100):
+ yield i
+ a = list(b)
+ self.assertEqual(a, list(range(1, len(a)+1)))
+ self.assertEqual(len(b), len(a))
+ self.assertLessEqual(len(b), i)
+ alloc = b.__alloc__()
+ self.assertGreater(alloc, len(b)) # including trailing null byte
+ b.__init__(g())
+ self.assertEqual(list(b), list(range(1, 100)))
+ self.assertEqual(len(b), 99)
+ alloc = b.__alloc__()
+ self.assertGreater(alloc, len(b))
+
def test_extend(self):
orig = b'hello'
a = bytearray(orig)