Skip to content

Commit f0ea126

Browse files
picnixzmiss-islington
authored andcommitted
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`. (cherry picked from commit 9af96f4) Co-authored-by: Bénédikt Tran <[email protected]>
1 parent 9c54248 commit f0ea126

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
@@ -458,11 +458,14 @@ estimate_log2_keysize(Py_ssize_t n)
458458

459459
/* This immutable, empty PyDictKeysObject is used for PyDict_Clear()
460460
* (which cannot fail and thus can do no allocation).
461+
*
462+
* See https://github.com/python/cpython/pull/127568#discussion_r1868070614
463+
* for the rationale of using dk_log2_index_bytes=3 instead of 0.
461464
*/
462465
static PyDictKeysObject empty_keys_struct = {
463466
_Py_IMMORTAL_REFCNT, /* dk_refcnt */
464467
0, /* dk_log2_size */
465-
0, /* dk_log2_index_bytes */
468+
3, /* dk_log2_index_bytes */
466469
DICT_KEYS_UNICODE, /* dk_kind */
467470
1, /* dk_version */
468471
0, /* dk_usable (immutable) */

0 commit comments

Comments
 (0)