diff options
author | Sergey B Kirpichev <skirpichev@gmail.com> | 2024-10-10 12:42:03 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-10 12:42:03 (GMT) |
commit | 87d7315ac57250046372b0d9ae4619ba619c8c87 (patch) | |
tree | 3faebb9b68976d101e1f0433f4c8eb1e3e65c4b1 /Lib/test/test_struct.py | |
parent | e4cab488d4445e8444932f3bed1c329c0d9e5038 (diff) | |
download | cpython-87d7315ac57250046372b0d9ae4619ba619c8c87.zip cpython-87d7315ac57250046372b0d9ae4619ba619c8c87.tar.gz cpython-87d7315ac57250046372b0d9ae4619ba619c8c87.tar.bz2 |
gh-125118: don't copy arbitrary values to _Bool in the struct module (GH-125169)
memcopy'ing arbitrary values to _Bool variable triggers undefined
behaviour. Avoid this.
We assume that `false` is represented by all zero bytes.
Credits to Alex Gaynor.
Co-authored-by: Sam Gross <colesbury@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Diffstat (limited to 'Lib/test/test_struct.py')
-rw-r--r-- | Lib/test/test_struct.py | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py index e3193c7..04ec3ed 100644 --- a/Lib/test/test_struct.py +++ b/Lib/test/test_struct.py @@ -540,6 +540,9 @@ class StructTest(ComplexesAreIdenticalMixin, unittest.TestCase): for c in [b'\x01', b'\x7f', b'\xff', b'\x0f', b'\xf0']: self.assertTrue(struct.unpack('>?', c)[0]) + self.assertTrue(struct.unpack('<?', c)[0]) + self.assertTrue(struct.unpack('=?', c)[0]) + self.assertTrue(struct.unpack('@?', c)[0]) def test_count_overflow(self): hugecount = '{}b'.format(sys.maxsize+1) |