GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [3.14] gh-142831: Fix use-after-free in json encoder during re-entrant mutation (gh-142851) by ashm-dev · Pull Request #150078 · python/cpython

Conversation

@ashm-dev

@ashm-dev ashm-dev commented May 19, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Manual backport of #142851 to 3.14 (the bot couldn't cleanly cherry-pick due to refactors in main).

The fix had to be adapted because in 3.14 the dict/list iteration loops were not yet extracted into the _encoder_iterate_*_lock_held helpers introduced later in main. Added the Py_INCREF/Py_DECREF around each borrowed item/key/value inline in encoder_listencode_dict (both the PyMapping_Items and PyDict_Next paths) and encoder_listencode_list.

The two regression tests from the original PR were cherry-picked as-is.

Built --with-pydebug and ran ./python -m test test_json -v locally — all 218 tests pass.

  • Issue: Use-after-free in json.encoder mapping iteration via re-entrant key encoder #142831

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ashm-dev @kumaraditya303 @gpshead
pythongh-142831: Fix use-after-free in json encoder during re-entrant…
d5b9f8d
… mutation (pythongh-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.

Co-authored-by: Kumar Aditya <[email protected]>
Co-authored-by: Gregory P. Smith <[email protected]>
(cherry picked from commit 235fa72)
This was referenced May 19, 2026
Use-after-free in json.encoder mapping iteration via re-entrant key encoder #142831
Closed
gh-142831: Fix UAF in _json module #142851
Merged
@bedevere-app bedevere-app Bot added the awaiting review label May 19, 2026
gpshead
gpshead approved these changes May 20, 2026
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels May 20, 2026
@gpshead gpshead self-assigned this May 20, 2026
@gpshead
gpshead merged commit bba6c1d into python:3.14 May 20, 2026
56 of 57 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label May 20, 2026
@ashm-dev
ashm-dev deleted the backport-gh-142831-3.14 branch May 20, 2026 03:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@gpshead gpshead gpshead approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@gpshead gpshead

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@ashm-dev @gpshead
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.