Skip to content

Commit

Permalink
[3.12] pythongh-127563: use dk_log2_index_bytes=3 in empty dicts (p…
Browse files Browse the repository at this point in the history
…ythonGH-127568) (pythonGH-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 <[email protected]>
  • Loading branch information
miss-islington and picnixz authored Dec 12, 2024
1 parent b0615a8 commit 320a1dc
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,14 @@ estimate_log2_keysize(Py_ssize_t n)

/* This immutable, empty PyDictKeysObject is used for PyDict_Clear()
* (which cannot fail and thus can do no allocation).
*
* See https://github.com/python/cpython/pull/127568#discussion_r1868070614
* for the rationale of using dk_log2_index_bytes=3 instead of 0.
*/
static PyDictKeysObject empty_keys_struct = {
_Py_IMMORTAL_REFCNT, /* dk_refcnt */
0, /* dk_log2_size */
0, /* dk_log2_index_bytes */
3, /* dk_log2_index_bytes */
DICT_KEYS_UNICODE, /* dk_kind */
1, /* dk_version */
0, /* dk_usable (immutable) */
Expand Down

0 comments on commit 320a1dc

Please sign in to comment.