https://github.com/python/cpython/commit/9af96f440618304e7cc609c246e1f8c8b2d7a119 commit: 9af96f440618304e7cc609c246e1f8c8b2d7a119 branch: main author: Bénédikt Tran <[email protected]> committer: encukou <[email protected]> date: 2024-12-10T16:58:17+01:00 summary:
gh-127563: use `dk_log2_index_bytes=3` in empty dicts (GH-127568) This fixes a UBSan failure (unaligned zero-size memcpy) in `dictobject.c`. files: M Objects/dictobject.c diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 1c9f86438dadc3..05c93a3e448181 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -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 */ _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
