Created on 2015-06-08 11:57 by pkt, last changed 2022-04-11 14:58 by admin. This issue is now closed.
# PyDict_Merge:
#
# 1 for (i = 0, n = DK_SIZE(other->ma_keys); i < n; i++) {
# ...
# 3 entry = &other->ma_keys->dk_entries[i];
# ...
# 2 if (insertdict(mp, entry->me_key,
# entry->me_hash,
# value) != 0)
# return -1;
# ...
# }
#
# 1. n is set once
# 2. it's possible to run a custom __eq__ method from inside the insertdict.
# __eq__ clears the "other" dict. "n" variables is now out of date
# 3. out of bounds read
#
# CRASH:
# ------
#
# * thread #1: tid = 27715, 0x080d1c1d python`insertdict(mp=0xb71d66f4, key=0x61682044, hash=543582496, value=0xb71d6664) + 132 at dictobject.c:819, name = 'python', stop reason = invalid address (fault address: 0x61682050)
# frame #0: 0x080d1c1d python`insertdict(mp=0xb71d66f4, key=0x61682044, hash=543582496, value=0xb71d6664) + 132 at dictobject.c:819
# 816 if (ep == NULL) {
# 817 return -1;
# 818 }
# -> 819 assert(PyUnicode_CheckExact(key) || mp->ma_keys->dk_lookup == lookdict);
# 820 Py_INCREF(value);
# 821 MAINTAIN_TRACKING(mp, key, value);
# 822 old_value = *value_addr;
#
ping
ping
ping
Thanks for the report, paul. Please do not ping an issue after a day. Quoting from https://docs.python.org/devguide/patch.html?#reviewing "If your patch has not received any notice from reviewers (i.e., no comment made) after one month, first “ping” the issue on the issue tracker to remind the nosy list that the patch needs a review. If you don’t get a response within a few days after pinging the issue, then you can try emailing python-dev@python.org asking for someone to review your patch."
The tracker won't let me assign this to myself. Consider it assigned.
There are two parts to this fix. First, we raise a runtime exception if the other dict is modified during the update/merge. Second, refcounts must be incremented around the PyDict_GetItem and insertdict calls in case the key or value is otherwise deallocated. Patch attached.
Hmm, I just wrote a very similar patch. Tell me what you think. :)
If the tracker had let me assign the issue, you need not have wasted your time. Oh well. Indeed, your patch looks very similar to mine.
Oh, he still might have written the patch, after all there isn't a lot of operational difference between the email that says "assigned to XXX" and the email that contains your text "consider this assigned". However, Benjamin has given you developer privs on the tracker, so in the future you can use assignment if you wish to :)
New changeset 37fed8b02f00 by Benjamin Peterson in branch '3.3': protect against mutation of the dict during insertion (closes #24407) https://hg.python.org/cpython/rev/37fed8b02f00 New changeset 75da5acbfbe4 by Benjamin Peterson in branch '3.4': merge 3.3 (#24407) https://hg.python.org/cpython/rev/75da5acbfbe4 New changeset 6a7ee97cb0b1 by Benjamin Peterson in branch '3.5': merge 3.4 (#24407) https://hg.python.org/cpython/rev/6a7ee97cb0b1 New changeset 88814ddd5e9e by Benjamin Peterson in branch 'default': merge 3.5 (#24407) https://hg.python.org/cpython/rev/88814ddd5e9e
nosy:
+ python-dev
messages:
+ msg246293
resolution: fixed
stage: needs patch -> resolved
components:
+ Interpreter Core
stage: needs patch