| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
In encoder_encode_key_value(), key is a borrowed reference from
PyDict_Next(). If the default callback mutates or clears the dict,
key becomes a dangling pointer. The error path then calls
_PyErr_FormatNote("%R", key) on freed memory.
Fix by holding strong references to key and value unconditionally
during encoding, not just in the free-threading build.
…j31cp.rst Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
# Conflicts: # Lib/test/test_json/test_dump.py
| Py_INCREF(key); | ||
| Py_INCREF(value); | ||
| #endif | ||
| if (encoder_encode_key_value(s, writer, first, dct, key, value, |
There was a problem hiding this comment.
reviewer note for the future: I explored if we could deterministically understand if encoder_encode_key_value was going to call user code which could lead to the problem... it's too complicated. while a couple heuristics exist for a subset of cases, they'd be fragile.
Sorry, something went wrong.
|
Sorry, @raminfp and @gpshead, I could not cleanly backport this to 3.14 due to a conflict. cherry_picker 8a466fa3d90a9e1f04d23c05ee2cf3f3c406ba30 3.14 |
Sorry, something went wrong.
…der (pythonGH-145245) In encoder_encode_key_value(), key is a borrowed reference from PyDict_Next(). If the default callback mutates or clears the dict, key becomes a dangling pointer. The error path then calls _PyErr_FormatNote("%R", key) on freed memory. Fix by holding strong references to key and value unconditionally during encoding, not just in the free-threading build. Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
| Back | FazBrowse Home | New Git URL |
Fix use-after-free in encoder_encode_key_value() where borrowed references to dict keys from PyDict_Next() can become dangling pointers if the default callback mutates the dictionary during encoding.