From: Sergey B Kirpichev Date: Thu, 10 Oct 2024 14:56:49 +0000 (+0300) Subject: [3.12] gh-125118: don't copy arbitrary values to _Bool in the struct module (GH-12516... X-Git-Tag: v3.12.8~234 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=67f8302b9c94079f73dba23eaa47443fcb6008ad;p=thirdparty%2FPython%2Fcpython.git [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 87d7315ac57250046372b0d9ae4619ba619c8c87) 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 39ca78cece1f..c683e5dd6c47 100644 --- a/Lib/test/test_struct.py +++ b/Lib/test/test_struct.py @@ -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('