bytearray.resize() must not clear the object on error (memory allocation failure)
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia dal percorso di bytearray.resize() e dal suo utilizzo di _PyBytes_Resize(), quindi riproduci l’esempio fornito di _testcapi.set_nomemory(). Il lavoro è completato quando un resize fallito solleva MemoryError preservando il contenuto di bytearray, con un test di regressione che copra questo comportamento.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- backend
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100