Skip to content

Commit acf05aa

Browse files
[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 9af96f4) Co-authored-by: Bénédikt Tran <[email protected]>
1 parent 8b28ded commit acf05aa

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Objects/dictobject.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -624,11 +624,14 @@ estimate_log2_keysize(Py_ssize_t n)
624624

625625
/* This immutable, empty PyDictKeysObject is used for PyDict_Clear()
626626
* (which cannot fail and thus can do no allocation).
627+
*
628+
* See https://github.com/python/cpython/pull/127568#discussion_r1868070614
629+
* for the rationale of using dk_log2_index_bytes=3 instead of 0.
627630
*/
628631
static PyDictKeysObject empty_keys_struct = {
629632
_Py_IMMORTAL_REFCNT, /* dk_refcnt */
630633
0, /* dk_log2_size */
631-
0, /* dk_log2_index_bytes */
634+
3, /* dk_log2_index_bytes */
632635
DICT_KEYS_UNICODE, /* dk_kind */
633636
#ifdef Py_GIL_DISABLED
634637
{0}, /* dk_mutex */

0 commit comments

Comments
 (0)