python / python/cpython

3.13.2: cast in Py_XDECREF causes runtime failures with immortal objects

オープン
#135,746 コメント 17 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

interpreter-core OS-windows topic-C-API type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Py_XDECREF/Py_DECREF と _Py_IsImmortal の呼び出しパスから始め、報告されている immortal reference count を使って Windows VS2022 /RTC1 の失敗を再現します。cast の動作を提案されたマスキングと比較し、その後、関連する CPython テストを使って失敗が解消されたことを確認します。この issue では特定のソースファイルやテストは指定されていません。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
c, python
領域
backend, operating-systems
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。