[3.8] bpo-35714: Reject null characters in struct format strings (GH-… · python/cpython@5ff5edf

Original file line numberDiff line numberDiff line change

@@ -652,6 +652,13 @@ def test_format_attr(self):

652652

s2 = struct.Struct(s.format.encode())

653653

self.assertEqual(s2.format, s.format)

654654
655+

def test_issue35714(self):

656+

# Embedded null characters should not be allowed in format strings.

657+

for s in '\0', '2\0i', b'\0':

658+

with self.assertRaisesRegex(struct.error,

659+

'embedded null character'):

660+

struct.calcsize(s)

661+
655662
656663

class UnpackIteratorTest(unittest.TestCase):

657664

"""