-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-35714: Reject null characters in struct format strings #16928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-35714: Reject null characters in struct format strings #16928
Conversation
struct.error is now raised if there is a null character in a struct format string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Lib/test/test_struct.py
Outdated
@@ -652,6 +652,13 @@ def test_format_attr(self): | |||
s2 = struct.Struct(s.format.encode()) | |||
self.assertEqual(s2.format, s.format) | |||
|
|||
def test_issue35714(self): | |||
# Embedded null characters should not be allowed in format strings. | |||
for s in '\0', '\144\u0064\000xf', 'd\0d', '>ih\0', '=Q\0\0': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the difference between all these cases? Why they are needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The embedded null is located at different positions of the string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And why it is handled differently depending on the position?
I would test with '\0'
, '2\0i'
and b'\0'
.
Thanks @ZackerySpytz for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7, 3.8, 3.9. |
…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 <[email protected]>
GH-20373 is a backport of this pull request to the 3.9 branch. |
…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 <[email protected]>
GH-20374 is a backport of this pull request to the 3.8 branch. |
…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 <[email protected]>
GH-20375 is a backport of this pull request to the 3.7 branch. |
…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 <[email protected]>
GH-20376 is a backport of this pull request to the 3.6 branch. |
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 <[email protected]>
…honGH-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 <[email protected]>
…honGH-16928) (pythonGH-20419) struct.error is now raised if there is a null character in a struct format string. (cherry picked from commit 3f59b55) (cherry picked from commit 5ff5edf) Co-authored-by: Zackery Spytz <[email protected]>
…16928) (GH-20419) struct.error is now raised if there is a null character in a struct format string. (cherry picked from commit 3f59b55) (cherry picked from commit 5ff5edf) Co-authored-by: Zackery Spytz <[email protected]>
struct.error is now raised if there is a null character in a struct
format string.
https://bugs.python.org/issue35714