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 — [backport to 3.5] bpo-29438: Fixed use-after-free in key sharing dict by methane · Pull Request #40 · python/cpython

Conversation

@methane

@methane methane commented Feb 12, 2017

Copy link
Copy Markdown
Member

No description provided.

Sorry, something went wrong.

Uh oh!

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

All reactions
@methane
bpo-29438: Fixed use-after-free in key sharing dict
af40edf
@methane methane added the type-bug An unexpected behavior, bug, or error label Feb 12, 2017
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Feb 12, 2017
@methane methane changed the title bpo-29438: Fixed use-after-free in key sharing dict [backport to 3.5] bpo-29438: Fixed use-after-free in key sharing dict Feb 12, 2017
serhiy-storchaka
serhiy-storchaka reviewed Feb 12, 2017
View reviewed changes
Comment thread Objects/dictobject.c
}
if (value == NULL) {
res = PyDict_DelItem(dict, key);
if (cached != ((PyDictObject *)dict)->ma_keys) {

@serhiy-storchaka serhiy-storchaka Feb 12, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why these lines are deleted?

Sorry, something went wrong.

Uh oh!

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

All reactions

@methane methane Feb 12, 2017

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Python 3.5, PyDict_DelItem won't resize dict. So cached == dict->ma_keys in most cases.

One exception is callback called by weakref or __del__ inserts some items to the dict and resize happened.
In this case, cached != CACHED_KEYS(tp), so DK_DECREF(cached) will be "use-after-free".

In such case, the insertion from the callback would update CACHED_KEYS(tp) correctly.
So clearing CACHED_KEYS(tp) doesn't make sense for most case.

Even when the callback inserts items through __dict__ (not regular attribute access), skipping CACHED_KEYS(tp) = NULL
doesn't cause uncontrolled memory growth. And it happens very rarely.
So I think this code is not worth enough.

Sorry, something went wrong.

Uh oh!

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

All reactions
serhiy-storchaka
serhiy-storchaka approved these changes Feb 12, 2017
View reviewed changes
@methane
methane merged commit 06a4fcb into python:3.5 Feb 13, 2017
@methane
methane deleted the bpo29438/py35 branch February 13, 2017 00:16
@Mariatta Mariatta added the cherry-pick for 3.5 label Feb 14, 2017
@ziegenbalg ziegenbalg mentioned this pull request Nov 30, 2022
double free in io.TextIOWrapper #72573
Closed
jaraco pushed a commit that referenced this pull request Dec 2, 2022
@Mariatta
Use cherry-picker v 0.2.5 (GH-40)
e954502
oraluben pushed a commit to oraluben/cpython that referenced this pull request Jun 25, 2023
@Fidget-Spinner
fix: add multiple jump target to metadata, special ops can be jump ta…
426daf1
…rgets (python#40)
@gvanrossum gvanrossum mentioned this pull request Aug 22, 2023
heap-use-after-free in _PyFunction_LookupByVersion #108253
Closed
@LinanV LinanV mentioned this pull request Oct 23, 2023
Objects/typeobject.c: No such file or directory. #111203
Closed
@kcatss kcatss mentioned this pull request Feb 20, 2024
Use After Free at _heapreplace_max #115706
Closed
@ngoldbaum ngoldbaum mentioned this pull request Sep 23, 2024
Crash running PyO3 tests with --test-threads=1000 #124375
Closed
This was referenced Feb 11, 2025
segmentfault when pip installing setuptools #129992
Closed
segmentfault when pip installing setuptools #129993
Closed
@DominiquePACCO DominiquePACCO mentioned this pull request Jun 3, 2025
PdfWriter add_page adds (re)writes old page instead of new #135062
Closed
@sergey-miryanov sergey-miryanov mentioned this pull request Dec 18, 2025
Observed memory leak in ssl library: Python 3.14 GC issue #142516
Closed
johnslavik pushed a commit to johnslavik/cpython that referenced this pull request Dec 19, 2025
@DinoV
Merge pull request python#40 from hugovk/3.15-lazy-rm-get_lazy_modules
b437afb
Remove `get_lazy_modules` from docs
@ngoldbaum ngoldbaum mentioned this pull request Mar 6, 2026
Remove deprecated and undocumented function ctypes.SetPointerType #133866
Closed
SonicField added a commit to SonicField/cpython that referenced this pull request Apr 15, 2026
@SonicField
Add bytecode_offset=-1 self-enforcing invariant + regression test
13f3720
Move bytecode_offset=-1 initialization into hir_c_alloc_instr so the
invariant is structurally enforced — even if hir_c_init_instr is
accidentally skipped, bytecode_offset will be -1 (not 0 from calloc).

Add runtime regression test in hir_instr_c_verify.cpp that verifies
the invariant for all three allocation paths (raw alloc, init_instr,
init_deopt). Runs at startup via __attribute__((constructor)).

Addresses gap flagged 5 times (Pythia python#14, python#40, python#59, librarian x2).
@johng johng mentioned this pull request Jul 19, 2026
use-after-free: functools partial #154189
Closed
@djarfluka djarfluka mentioned this pull request Sep 12, 2026
Heap UAF in io.TextIOWrapper read path via reentrant detach() #157363
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@serhiy-storchaka serhiy-storchaka serhiy-storchaka approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

type-bug An unexpected behavior, bug, or error

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.

4 participants

@methane @serhiy-storchaka @Mariatta @the-knights-who-say-ni
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.