https://github.com/python/cpython/commit/313544eb0381d868b4f8b351a0ca808c313af698
commit: 313544eb0381d868b4f8b351a0ca808c313af698
branch: 3.11
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: pablogsal <pablog...@gmail.com>
date: 2025-06-16T14:51:04+02:00
summary:

[3.11] gh-127563: use `dk_log2_index_bytes=3` in empty dicts (GH-127568) 
(GH-127813) (#135463)

[3.12] gh-127563: use `dk_log2_index_bytes=3` in empty dicts (GH-127568) 
(GH-127813)

This fixes a UBSan failure (unaligned zero-size memcpy) in `dictobject.c`.
(cherry picked from commit 9af96f440618304e7cc609c246e1f8c8b2d7a119)

(cherry picked from commit 320a1dcd97110598a4fe6ae1c0018cd3decc408f)

Co-authored-by: Bénédikt Tran <10796600+picn...@users.noreply.github.com>

files:
M Objects/dictobject.c

diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 69a4a865103c18..0e9c6d24e48338 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -449,11 +449,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 = {
         1, /* dk_refcnt */
         0, /* dk_log2_size */
-        0, /* dk_log2_index_bytes */
+        3, /* dk_log2_index_bytes */
         DICT_KEYS_UNICODE, /* dk_kind */
         1, /* dk_version */
         0, /* dk_usable (immutable) */

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: arch...@mail-archive.com

Reply via email to