3.13.2: cast in Py_XDECREF causes runtime failures with immortal objects · Issue #135746 · python/cpython · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

3.13.2: cast in Py_XDECREF causes runtime failures with immortal objects #135746

Open
@Jejos

Description

@Jejos

Bug report

Bug description:

In Python 3.13.2 I use

Py_XDECREF(PyObject *op) 

It is called at the end of a function-call to load an image (cv2.imread) which fails, resulting in a None value (not NULL!). For Python 3.9 Py_XDECREF works just fine, without crash. For Python 3.13.2 the program, compiled with VS2022 (64 Bit), raises a "Run-Time Check Failure #1 - A cast to a smaller data type has caused a loss of data." and my application crashes ("/RTC1 = Basic Runtime Checks enabled").

I followed up the calls:

    Py_DECREF
        _Py_IsImmortal
            #elif SIZEOF_VOID_P > 4
                _Py_CAST(PY_INT32_T, op->ob_refcnt)     <-- crash

The value is

op->ob_refcnt == 0x0000000100000000

To fix this problem, I propose, that the type cast to 32 bit should be changed to

_Py_CAST(PY_INT32_T, op->ob_refcnt & 0xFFFFFFFF)

CPython versions tested on:

3.13

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      TMZ Celebrity News – Breaking Stories, Videos & Gossip

      Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

      Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

      🎥 Watch TMZ Live

      TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.