Skip to content

Commit 313544e

Browse files
[3.11] gh-127563: use dk_log2_index_bytes=3 in empty dicts (GH-127568) (GH-127813) (#135463)
[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) (cherry picked from commit 320a1dc) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
1 parent c96ab19 commit 313544e

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

450450
/* This immutable, empty PyDictKeysObject is used for PyDict_Clear()
451451
* (which cannot fail and thus can do no allocation).
452+
*
453+
* See https://github.com/python/cpython/pull/127568#discussion_r1868070614
454+
* for the rationale of using dk_log2_index_bytes=3 instead of 0.
452455
*/
453456
static PyDictKeysObject empty_keys_struct = {
454457
1, /* dk_refcnt */
455458
0, /* dk_log2_size */
456-
0, /* dk_log2_index_bytes */
459+
3, /* dk_log2_index_bytes */
457460
DICT_KEYS_UNICODE, /* dk_kind */
458461
1, /* dk_version */
459462
0, /* dk_usable (immutable) */

0 commit comments

Comments
 (0)