diff options
author | Brian Schubert <brianm.schubert@gmail.com> | 2024-09-20 10:08:59 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-20 10:08:59 (GMT) |
commit | 63f196090f90cbfe5f698824655f74dea5cb2b29 (patch) | |
tree | 53673a94db1e9a94bea99f0cc6af3611d910d5a0 /Lib/test/test_struct.py | |
parent | baa3550bc3a119f41cc4eaed5373f9d695208e8e (diff) | |
download | cpython-63f196090f90cbfe5f698824655f74dea5cb2b29.zip cpython-63f196090f90cbfe5f698824655f74dea5cb2b29.tar.gz cpython-63f196090f90cbfe5f698824655f74dea5cb2b29.tar.bz2 |
gh-124248: Fix crash in struct when processing 0p fields (#124251)
Diffstat (limited to 'Lib/test/test_struct.py')
-rw-r--r-- | Lib/test/test_struct.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py index 5508cc3..bdbf880 100644 --- a/Lib/test/test_struct.py +++ b/Lib/test/test_struct.py @@ -96,6 +96,13 @@ class StructTest(unittest.TestCase): ('10s', b'helloworld', b'helloworld', b'helloworld', 0), ('11s', b'helloworld', b'helloworld\0', b'helloworld\0', 1), ('20s', b'helloworld', b'helloworld'+10*b'\0', b'helloworld'+10*b'\0', 1), + ('0p', b'helloworld', b'', b'', 1), + ('1p', b'helloworld', b'\x00', b'\x00', 1), + ('2p', b'helloworld', b'\x01h', b'\x01h', 1), + ('10p', b'helloworld', b'\x09helloworl', b'\x09helloworl', 1), + ('11p', b'helloworld', b'\x0Ahelloworld', b'\x0Ahelloworld', 0), + ('12p', b'helloworld', b'\x0Ahelloworld\0', b'\x0Ahelloworld\0', 1), + ('20p', b'helloworld', b'\x0Ahelloworld'+9*b'\0', b'\x0Ahelloworld'+9*b'\0', 1), ('b', 7, b'\7', b'\7', 0), ('b', -7, b'\371', b'\371', 0), ('B', 7, b'\7', b'\7', 0), @@ -339,6 +346,7 @@ class StructTest(unittest.TestCase): def test_p_code(self): # Test p ("Pascal string") code. for code, input, expected, expectedback in [ + ('0p', b'abc', b'', b''), ('p', b'abc', b'\x00', b''), ('1p', b'abc', b'\x00', b''), ('2p', b'abc', b'\x01a', b'a'), @@ -580,6 +588,7 @@ class StructTest(unittest.TestCase): self.check_sizeof('187s', 1) self.check_sizeof('20p', 1) self.check_sizeof('0s', 1) + self.check_sizeof('0p', 1) self.check_sizeof('0c', 0) def test_boundary_error_message(self): |