Skip to content

Commit 9af96f4

Browse files
authored
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`.
1 parent cef0a90 commit 9af96f4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Objects/dictobject.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,11 +588,14 @@ estimate_log2_keysize(Py_ssize_t n)
588588

589589
/* This immutable, empty PyDictKeysObject is used for PyDict_Clear()
590590
* (which cannot fail and thus can do no allocation).
591+
*
592+
* See https://github.com/python/cpython/pull/127568#discussion_r1868070614
593+
* for the rationale of using dk_log2_index_bytes=3 instead of 0.
591594
*/
592595
static PyDictKeysObject empty_keys_struct = {
593596
_Py_DICT_IMMORTAL_INITIAL_REFCNT, /* dk_refcnt */
594597
0, /* dk_log2_size */
595-
0, /* dk_log2_index_bytes */
598+
3, /* dk_log2_index_bytes */
596599
DICT_KEYS_UNICODE, /* dk_kind */
597600
#ifdef Py_GIL_DISABLED
598601
{0}, /* dk_mutex */

0 commit comments

Comments
 (0)