[3.11] gh-127563: use dk_log2_index_bytes=3 in empty dicts (GH-127568) (GH-127813) (#135463)
Some checks failed
Lint / lint (push) Has been cancelled
Tests / Check for source changes (push) Has been cancelled
Tests / Docs (push) Has been cancelled
Tests / Check if the ABI has changed (push) Has been cancelled
Tests / Check if generated files are up to date (push) Has been cancelled
Tests / Windows (push) Has been cancelled
Tests / macOS (push) Has been cancelled
Tests / Ubuntu (push) Has been cancelled
Tests / Ubuntu SSL tests with OpenSSL (push) Has been cancelled
Tests / Address sanitizer (push) Has been cancelled
Tests / All required checks pass (push) Has been cancelled

[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 9af96f4406)

(cherry picked from commit 320a1dcd97)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2025-06-16 14:51:04 +02:00 committed by GitHub
parent c96ab19ae4
commit 313544eb03
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -449,11 +449,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 = {
1, /* 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) */