readline.c: Missing NULL check on PyLong_FromLong
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Đọc Modules/readline.c quanh setup_readline và các lời gọi PyLong_FromLong gần dòng 1330-1331; trước tiên chạy trình tái hiện memory-hook _testcapi được cung cấp và kiểm tra PR được liên kết gh-154386. Được xem là hoàn tất khi đường dẫn out-of-memory bị ảnh hưởng không còn cho phép một đối tượng NULL đi tới readline accessors, và các bài kiểm tra CPython liên quan đều đạt.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- c, python
- Lĩnh vực
- cli
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 25/100