readline.c: Missing NULL check on PyLong_FromLong
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug report
Bug description:
Original gist: https://gist.github.com/devdanzin/60aed55f44fba133ee2d34d46aa8d197
readline.c: Missing NULL check on PyLong_FromLong in setup_readline
Summary
PyLong_FromLong(0L)at lines 1418-1419 stored inbegidx/endidxwithout NULL check. On OOM during module init,readline.get_begidx()doesPy_NewRef(NULL)→ segfault.Reproducer
import _testcapi, sys if "readline" in sys.modules: del sys.modules["readline"] for n in range(1, 80): if "readline" in sys.modules: del sys.modules["readline"] _testcapi.set_nomemory(n, 0) try: import readline _testcapi.remove_mem_hooks() break except MemoryError: _testcapi.remove_mem_hooks() except ImportError: _testcapi.remove_mem_hooks() except: _testcapi.remove_mem_hooks() # Assertion: obj != NULL in PyStackRef_FromPyObjectSteal
The original gist said we should check the result of PyLong_FromLong(0L), but I think this is a false positive, because 0 is small int and should not failed while creating a Python int object from it.
However there are other line of code in this file for calling PyLong_FromLong with begidx/endidx withoud check the result:
I guess the LLM found a real bug but reported it at the wrong place. Either way, we should fix it.
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
- gh-154386
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Lies Modules/readline.c im Bereich von setup_readline und den PyLong_FromLong-Aufrufen in der Nähe der Zeilen 1330–1331; führe zuerst den bereitgestellten _testcapi memory-hook-Reproducer aus und prüfe den verknüpften PR gh-154386. Erledigt bedeutet, dass der betroffene Out-of-Memory-Pfad nicht mehr zulässt, dass ein NULL-Objekt readline accessors erreicht, und dass die relevanten CPython-Tests bestehen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- c, python
- Bereich
- cli
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100