Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ctypes: NULL-dereference when using py_result restype #132417

Closed
Labels
extension-modulesC modules in the Modules dirtopic-ctypestype-crashA hard crash of the interpreter, possibly with a core dump
@NicolasT

Description

@NicolasT

Crash report

What happened?

When usingctypes with a function which returns aPyObject *, usingrestypectypes.py_object, and the function returnsNULL, there's aPy_DECREF of the result, leading to a segfault:

importctypesPyErr_Occurred=ctypes.pythonapi.PyErr_OccurredPyErr_Occurred.argtypes= []PyErr_Occurred.restype=ctypes.py_objectPyErr_Occurred()

The issue lies inGetResult: whenO_get is the result handler, it callsPy_DECREF on the result value, even though that can beNULL.O_get handles theNULL case correctly, setting an exception if none was set, and passing on theNULL. Code after thePy_DECREF inGetResult also handles theNULL case correctly, so changing thePy_DECREF into aPy_XDECREF makes things work.

Pull request incoming.

CPython versions tested on:

CPython 3.10, CPython 3.13, CPython main branch

Operating systems tested on:

Linux

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

Python 3.14.0a7+ (heads/main-dirty:deda47d6e18, Apr 11 2025, 20:18:59) [GCC 14.2.1 20240912 (Red Hat 14.2.1-3)]

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirtopic-ctypestype-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


      [8]ページ先頭

      ©2009-2025 Movatter.jp