readline.c: Missing NULL check on PyLong_FromLong
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
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
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Leia Modules/readline.c em torno de setup_readline e das chamadas a PyLong_FromLong próximas às linhas 1330-1331; primeiro execute o reproducer de memory-hook fornecido de _testcapi e inspecione o PR vinculado gh-154386. Considera-se concluído quando o caminho afetado de falta de memória não permitir mais que um objeto NULL chegue a readline accessors e os testes relevantes do CPython passarem.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- c, python
- Domínio
- cli
- Tipo de issue
- Bug
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 25/100