[3.13] gh-142831: Fix use-after-free in json encoder during re-entrant mutation (gh-142851) (#150079)
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>
S
Shamil committed
e87baa8d24f08a1b71a1c9ceb4fbf26824d48239
Parent: 792a552
Committed by GitHub <noreply@github.com>
on 5/20/2026, 3:33:22 AM