From: Sergey B Kirpichev Date: Thu, 10 Oct 2024 12:42:03 +0000 (+0300) Subject: gh-125118: don't copy arbitrary values to _Bool in the struct module (GH-125169) X-Git-Tag: v3.14.0a1~93 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=87d7315ac57250046372b0d9ae4619ba619c8c87;p=thirdparty%2FPython%2Fcpython.git 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 Co-authored-by: Victor Stinner Co-authored-by: Petr Viktorin --- diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py index e3193c7863fb..04ec3ed0837c 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('