]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.14] gh-142831: Fix use-after-free in json encoder during re-entrant mutation ...
authorShamil <ashm.tech@proton.me>
Wed, 20 May 2026 03:31:43 +0000 (06:31 +0300)
committerGitHub <noreply@github.com>
Wed, 20 May 2026 03:31:43 +0000 (20:31 -0700)
commitbba6c1d9d5721e763df88af187bc0a531e1708b6
tree261a32bf330d19011f30206b15196df698ed6e7f
parentaccfbb693f09837ff90a3f5b03d1d4be97cb898a
[3.14] gh-142831: Fix use-after-free in json encoder during re-entrant mutation (gh-142851) (#150078)

gh-142831: Fix use-after-free in json encoder during re-entrant mutation (gh-142851)

User callbacks invoked during JSON encoding (e.g. the `default` callback or
a custom string encoder) can mutate or clear the dict or sequence being
encoded, invalidating borrowed references to items, keys, and values. Hold
strong references unconditionally while iterating.

(cherry picked from commit 235fa7244a0474c492ae98ee444529c7ba2a9047)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
Lib/test/test_json/test_speedups.py
Misc/NEWS.d/next/Library/2025-12-17-04-10-35.gh-issue-142831.ee3t4L.rst [new file with mode: 0644]
Modules/_json.c