From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Wed, 11 Dec 2024 08:24:14 +0000 (+0100) Subject: [3.13] gh-127563: use `dk_log2_index_bytes=3` in empty dicts (GH-127568) (GH-127798) X-Git-Tag: v3.13.2~215 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=acf05aa5d82f2d96581a6b5625371a44b4bd625b;p=thirdparty%2FPython%2Fcpython.git [3.13] gh-127563: use `dk_log2_index_bytes=3` in empty dicts (GH-127568) (GH-127798) This fixes a UBSan failure (unaligned zero-size memcpy) in `dictobject.c`. (cherry picked from commit 9af96f440618304e7cc609c246e1f8c8b2d7a119) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- diff --git a/Objects/dictobject.c b/Objects/dictobject.c index e82cd2d308ca..ff16a41b9a5d 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -624,11 +624,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_IMMORTAL_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 */