]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-127563: use `dk_log2_index_bytes=3` in empty dicts (GH-127568)
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>
Tue, 10 Dec 2024 15:58:17 +0000 (16:58 +0100)
committerGitHub <noreply@github.com>
Tue, 10 Dec 2024 15:58:17 +0000 (16:58 +0100)
This fixes a UBSan failure (unaligned zero-size memcpy) in `dictobject.c`.

Objects/dictobject.c

index 1c9f86438dadc3e4c7f2e8d3288d7de986560aeb..05c93a3e44818102ec569c4039ac67532c59496c 100644 (file)
@@ -588,11 +588,14 @@ estimate_log2_keysize(Py_ssize_t n)
 
 /* This immutable, empty PyDictKeysObject is used for PyDict_Clear()
  * (which cannot fail and thus can do no allocation).
+ *
+ * See https://github.com/python/cpython/pull/127568#discussion_r1868070614
+ * for the rationale of using dk_log2_index_bytes=3 instead of 0.
  */
 static PyDictKeysObject empty_keys_struct = {
         _Py_DICT_IMMORTAL_INITIAL_REFCNT, /* dk_refcnt */
         0, /* dk_log2_size */
-        0, /* dk_log2_index_bytes */
+        3, /* dk_log2_index_bytes */
         DICT_KEYS_UNICODE, /* dk_kind */
 #ifdef Py_GIL_DISABLED
         {0}, /* dk_mutex */