Skip to content

Commit d1caff7

Browse files
committed
Add tests
1 parent babf5ff commit d1caff7

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

‎Lib/test/test_bytes.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,15 @@ def test_fromhex(self):
517517
self.type2test.fromhex(data)
518518
self.assertIn('at position %s' % pos, str(cm.exception))
519519

520+
# gh-158583: Check for out of bounds reads (uninitialized bytes).
521+
# Create an array from a list to not overallocate.
522+
a = array.array('B', list(b'1234 ')) # Py_ISSPACE() loop
523+
self.assertEqual(self.type2test.fromhex(a), b'\x12\x34')
524+
525+
a = array.array('B', list(b'12345')) # Missing second digit
526+
with self.assertRaises(ValueError) as cm:
527+
self.type2test.fromhex(a)
528+
520529
def test_hex(self):
521530
self.assertRaises(TypeError, self.type2test.hex)
522531
self.assertRaises(TypeError, self.type2test.hex, 1)

0 commit comments

Comments
 (0)