OrderedDict.pop() can segfault when key equality changes between lookups
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ả
Crash report
What happened?
Calling collections.OrderedDict.pop() without a default value can cause a segmentation fault if the lookup key has a stateful __eq__ implementation that returns different results across successive comparisons.
The crash occurs on the current main branch.
Minimal reproducer:
from collections import OrderedDict
class K:
def __init__(self):
self.calls = 0
def __hash__(self):
return 12345
def __eq__(self, other):
self.calls += 1
return self.calls == 1
k1 = K()
k2 = K()
od = OrderedDict()
od[k1] = "value"
od.pop(k2)
Running this with a locally built CPython from main results in:
Segmentation fault (core dumped)
Expected behavior:
OrderedDict.pop()should not crash the interpreter.- It should either remove the matching item or raise
KeyErrorif the key is not found.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.16.0a0 (heads/fix-odict-pop-null-failobj:2ffab083782, Jul 28 2026, 12:31:11) [GCC 13.3.0]
Linked PRs
- gh-154818
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
Bắt đầu từ điểm vào OrderedDict.pop() và chạy trình tái hiện tối thiểu trên nhánh main của CPython được build cục bộ. Được xem là hoàn tất khi trình tái hiện không còn gây ra segmentation fault và pop() либо xóa mục khớp, либо phát sinh KeyError khi không tìm thấy khóa.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- backend
- 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
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 25/100