python / python/cpython

Crash when deleting decimal.Context.rounding through the descriptor

Open
#156,806 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

extension-modules type-crash
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Crash report

What happened?
import decimal
decimal.Context.rounding.__delete__(decimal.Context())
Segmentation fault (core dumped)

context_setround() passes the value to getround(), which calls
PyUnicode_Check() on it without checking it for NULL, and the setter is
called with NULL when the attribute is deleted. Plain del ctx.rounding is
safe, because context_setattr() rejects deletion — but it is bypassed by
calling the descriptor.

The other five Context getsets do not crash, but raise SystemError:

import decimal
decimal.Context.prec.__delete__(decimal.Context())
# SystemError: ../Objects/longobject.c:577: bad argument to internal function

Same for Emin, Emax, capitals and clamp.

CPython versions tested on:

3.15, 3.14, 3.13, 3.12

Operating systems tested on:

Windows

Output from running 'python -VV' on the command line:

Python 3.12.3 (main, Jan 8 2026, 11:30:50) [GCC 13.3.0] / Python 3.14.2 (main, Dec 17 2025, 21:10:36) [MSC v.1944 64 bit (AMD64)]

Linked PRs
  • gh-156807

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with decimal.Context.rounding.delete and trace the descriptor path through context_setround(), getround(), and context_setattr(). Compare deletion behavior across rounding, prec, Emin, Emax, capitals, and clamp; done means descriptor deletion no longer crashes or raises an unintended SystemError. Linked PR gh-156807 indicates the work is already underway.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.