pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/5221a10dde4a3853fe7ace316d95767648055109

aa60c69660fa.css" /> bpo-35714: Reject null characters in struct format strings (GH-16928) · python/cpython@5221a10 · GitHub
Skip to content

Commit 5221a10

Browse files
bpo-35714: Reject null characters in struct format strings (GH-16928)
struct.error is now raised if there is a null character in a struct format string. (cherry picked from commit 3f59b55) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
1 parent a729f4a commit 5221a10

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

Lib/test/test_struct.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,14 @@ def __del__(self):
671671
self.assertIn(b"Exception ignored in:", stderr)
672672
self.assertIn(b"C.__del__", stderr)
673673

674+
def test_issue35714(self):
675+
# Embedded null characters should not be allowed in format strings.
676+
for s in '\0', '2\0i', b'\0':
677+
with self.assertRaisesRegex(struct.error,
678+
'embedded null character'):
679+
struct.calcsize(s)
680+
681+
674682
class UnpackIteratorTest(unittest.TestCase):
675683
"""
676684
Tests for iterative unpacking (struct.Struct.iter_unpack).
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:exc:`struct.error` is now raised if there is a null character in a
2+
:mod:`struct` format string.

Modules/_struct.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,11 @@ prepare_s(PyStructObject *self)
12961296
size_t ncodes;
12971297

12981298
fmt = PyBytes_AS_STRING(self->s_format);
1299+
if (strlen(fmt) != (size_t)PyBytes_GET_SIZE(self->s_format)) {
1300+
PyErr_SetString(_structmodulestate_global->StructError,
1301+
"embedded null character");
1302+
return -1;
1303+
}
12991304

13001305
f = whichtable(&fmt);
13011306

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy