Skip to content

decimal: _decimal casts the value of its decimal_context ContextVar without a type check #161387

Closed

Description

@theosotr

Bug report

Summary

Arithmetic on Decimal values crashes the interpreter if the decimal_context context variable has been set to something that isn't a decimal.Context.

Expected: a TypeError when the variable does not hold a Context.

Reproducer

import contextvars
import decimal

decimal.getcontext() 
var = next(v for v in contextvars.copy_context() if v.name == "decimal_context")
var.set(1)
decimal.Decimal(1) + decimal.Decimal(2)
Segmentation fault (core dumped)

CPython versions tested on:

3.15

Operating systems tested on:

Linux

Linked PRs

Activity

  1. changed the title [-]_decimal` casts the value of its `decimal_context` ContextVar without a type check[/-] [+]`_decimal` casts the value of its `decimal_context` ContextVar without a type check[/+] on Nov 5, 2026
  2. changed the title [-]`_decimal` casts the value of its `decimal_context` ContextVar without a type check[/-] [+]decimal: `_decimal` casts the value of its `decimal_context` ContextVar without a type check[/+] on Nov 5, 2026
  3. added
    type-crashA hard crash of the interpreter, possibly with a core dump
    3.15bugs and security fixes
    and removed
    type-bugAn unexpected behavior, bug, or error
    3.15bugs and security fixes
    on Nov 5, 2026
  4. added 3 commits that reference this issue on Nov 6, 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 dirtype-crashA 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