bytearray.resize() must not clear the object on error (memory allocation failure)
オープン
まだ誰も着手していません。
interpreter-core
type-bug
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Python 3.15 reimplemented bytearray using an internal bytes object (to implement the bytearray.take_bytes() method). _PyBytes_Resize() is used internally to resize the bytearray object. Problem: if _PyBytes_Resize() fails, the bytearray object is cleared.
On Python 3.14, the bytearray is not cleared on resize failure.
The following example works on Python 3.14 but fails on Python 3.15.
import _testcapi
data = b'some data'
ba = bytearray(data)
try:
try:
_testcapi.set_nomemory(0)
ba.resize(1024)
except MemoryError:
pass
else:
raise AssertionError("expect MemoryError")
finally:
_testcapi.remove_mem_hooks()
if ba != data:
raise AssertionError(f"{ba} != {data}")
Linked PRs
- gh-157243
- gh-157340
- gh-157344
- gh-157350
- gh-157351
- gh-157352
- gh-157371
- gh-157375
- gh-157431
- gh-157619
- gh-157723
- gh-157811
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず bytearray.resize() のパスと _PyBytes_Resize() の使用箇所を確認し、次に提示された _testcapi.set_nomemory() の例を再現します。完了条件は、resize に失敗すると MemoryError が発生し、その際に bytearray の内容が保持されることです。この動作をカバーするリグレッションテストが必要です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100