Skip to content

DefaultAtomDict.__missing__ increfs the NULL from PyDict_GetItem leading to seg fault #277

Closed

Description

@theosotr

Summary

PyDict_GetItem returns a borrowed reference or NULL, and it suppresses exceptions raised by __hash__/__eq__. The result is passed to cppy::incref with no NULL check, so a key whose __hash__ raises on this lookup makes Py_INCREF(NULL) dereference a null pointer.

Environment

  • atom 0.13.0
  • Python 3.13
  • Debian 13 (trixie)

Reproducer

from atom.api import Atom, DefaultDict


class A(Atom):
    d = DefaultDict(missing=int)


class Key:
    n = 0

    def __hash__(self):
        Key.n += 1
        if Key.n == 3: 
            raise RuntimeError("Key.__hash__")
        return 1


a = A()
print(a.d[Key()])
Exception ignored in PyDict_GetItem(); consider using PyDict_GetItemRef() or PyDict_GetItemWithError():
Traceback (most recent call last):
  File "min.py", line 14, in __hash__
    raise RuntimeError("Key.__hash__")
RuntimeError: Key.__hash__
Segmentation fault (core dumped)

Activity

  1. added a commit that references this issue on Nov 3, 2026
  2. MatthieuDartiailh commented on Nov 3, 2026

    @MatthieuDartiailh
    Member

    Closed by #279

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions