python / python/cpython

`mmap.mmap.__setitem__` crashes when concurrently resized

未關閉
#157,335 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

extension-modules type-bug
主要語言
Python
星號
77.2k
分支
36k
PR 合併指標
PR 指標待擷取

描述

Bug report

Bug description:
import mmap
mm = mmap.mmap(-1, 100000)         
class mid:
    def __index__(self):
        mm.resize(8)           
        return 0
mm[90000] = mid()          

AddressSanitizer:DEADLYSIGNAL

==1==ERROR: AddressSanitizer: SEGV on unknown address 0xffffa1a0cf90 (pc 0xffffa1a2aff0 bp 0xffffd2152970 sp 0xffffd2152830 T0)
==1==The signal is caused by a WRITE memory access.
#0 0xffffa1a2aff0 in safe_byte_copy Modules/mmapmodule.c:406
#1 0xffffa1a2aff0 in mmap_ass_subscript_lock_held Modules/mmapmodule.c:1692
#2 0xffffa1a2aff0 in mmap_ass_subscript Modules/mmapmodule.c:1750
#3 0xaaaadf0a9860 in _PyEval_EvalFrameDefault Python/generated_cases.c.h:12634
#4 0xaaaadf970b1c in _PyEval_EvalFrame Include/internal/pycore_ceval.h:122
#5 0xaaaadf970b1c in _PyEval_Vector Python/ceval.c:2174
#6 0xaaaadf970b1c in PyEval_EvalCode Python/ceval.c:679
#7 0xaaaadfb6feb4 in run_mod Python/pythonrun.c:1509
#8 0xaaaadfb70d38 in _PyRun_File Python/pythonrun.c:1332
#9 0xaaaadfb74ffc in _PyRun_SimpleFile Python/pythonrun.c:544
#10 0xaaaadfb78dd0 in _PyRun_AnyFile Python/pythonrun.c:92
#11 0xaaaadfc4390c in pymain_run_file_obj Modules/main.c:478
#12 0xaaaadfc4390c in pymain_run_file Modules/main.c:494
#13 0xaaaadfc4390c in pymain_run_python Modules/main.c:804
#14 0xaaaadfc4390c in Py_RunMain Modules/main.c:891
#15 0xaaaadfc45c38 in pymain_main Modules/main.c:921
#16 0xaaaadfc45c38 in Py_BytesMain Modules/main.c:945
#17 0xffffa46f84c0 (/lib/aarch64-linux-gnu/libc.so.6+0x284c0) (BuildId: 27027b96e5b8c475fc327aa445bea1c71d37b4e2)
#18 0xffffa46f8594 in __libc_start_main (/lib/aarch64-linux-gnu/libc.so.6+0x28594) (BuildId: 27027b96e5b8c475fc327aa445bea1c71d37b4e2)
#19 0xaaaadf0ebeec in _start (/src/cpython/python+0x183beec) (BuildId: eba909a3db0adabacf151d7dc3081dda7999191a)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV Modules/mmapmodule.c:406 in safe_byte_copy
==1==ABORTING

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs
  • gh-157438

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 reproducer 和 Modules/mmapmodule.c 中的堆疊追蹤位置開始,尤其是第 406 行的 safe_byte_copy 和第 1692 行附近的 mmap_ass_subscript_lock_held。使用 AddressSanitizer 執行範例,並驗證在 setitem 期間調整大小不再當機;gh-157438 已經連結到此 issue。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
c, python
領域
operating-systems
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
描述清楚
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。