There was an error while loading. Please reload this page.
1 parent babf5ff commit d1caff7Copy full SHA for d1caff7
1 file changed
Lib/test/test_bytes.py
@@ -517,6 +517,15 @@ def test_fromhex(self):
517
self.type2test.fromhex(data)
518
self.assertIn('at position %s' % pos, str(cm.exception))
519
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
529
def test_hex(self):
530
self.assertRaises(TypeError, self.type2test.hex)
531
self.assertRaises(TypeError, self.type2test.hex, 1)
0 commit comments