mirror of
https://github.com/python/cpython.git
synced 2025-08-09 03:19:15 +00:00
[3.12] gh-125118: don't copy arbitrary values to _Bool in the struct module (GH-125169) (#125265)
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.
(cherry picked from commit 87d7315ac5
)
Co-authored-by: Sam Gross <colesbury@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
This commit is contained in:
parent
74df3a79d3
commit
67f8302b9c
3 changed files with 6 additions and 3 deletions
|
@ -529,6 +529,9 @@ class StructTest(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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue