10000 [3.12] gh-127563: use `dk_log2_index_bytes=3` in empty dicts (GH-1275… · python/cpython@320a1dc · GitHub
[go: up one dir, main page]

Skip to content

Commit 320a1dc

Browse files
[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 9af96f4) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
1 parent b0615a8 commit 320a1dc

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)
0