aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Objects/dictobject.c
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2025-06-16 14:51:04 +0200
committerGitHub <noreply@github.com>2025-06-16 14:51:04 +0200
commit313544eb0381d868b4f8b351a0ca808c313af698 (patch)
tree19a2cb806244becc9ae877bd6d2e5debcdcd813f /Objects/dictobject.c
parentc96ab19ae460911e40ffa502f1bf945ab6c53a2e (diff)
downloadcpython-3.11.tar.gz
cpython-3.11.zip
[3.11] gh-127563: use `dk_log2_index_bytes=3` in empty dicts (GH-127568) (GH-127813) (#135463)3.11
[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+picnixz@users.noreply.github.com>
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r--Objects/dictobject.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 69a4a865103..0e9c6d24e48 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) */