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 — decimal: crash when a re-entrant __bool__ deallocates the Context during Context.flags assignment or comparison · Issue #155493 · python/cpython

decimal: crash when a re-entrant __bool__ deallocates the Context during Context.flags assignment or comparison #155493

New issue
Copy link
New issue
Copy link
Open
Open
decimal: crash when a re-entrant __bool__ deallocates the Context during Context.flags assignment or comparison#155493
Copy link
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump

Description

@tonghuaroot
tonghuaroot
opened on Aug 10, 2026
Issue body actions

Bug report

Context.flags (and traps) is a SignalDict that borrows a pointer to
flags owned by its Context. signaldict_setitem and
signaldict_richcompare read that pointer after calling back into Python
(PyObject_IsTrue, i.e. the value's __bool__), which can deallocate the
Context. gh-146011 cleared the borrowed pointer on Context teardown and
guarded signaldict_repr, but these two methods were left unguarded, so the
same teardown leaves them dereferencing a NULL pointer and crashing.

Assignment:

import decimal, gc
ctx = decimal.Context()
flags = ctx.flags
class Evil:
    def __bool__(self):
        global ctx; del ctx; gc.collect()
        return True
flags[decimal.InvalidOperation] = Evil()   # segfault

Comparison:

import decimal, gc
ctx = decimal.Context()
other = ctx.flags.copy()
class Evil:
    def __bool__(self):
        global ctx; del ctx; gc.collect()
        return True
other[decimal.InvalidOperation] = Evil()
ctx.flags == other                          # segfault

Both crash with SIGSEGV on current main; the affected code exists on 3.13+.

Linked PRs

  • gh-155493: Fix crash in decimal SignalDict on re-entrant Context teardown #155494

Activity

  1. StanFromIreland
    added
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    type-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
    on Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirC modules in the Modules dirtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — 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.