Dialog about overrun of a stack-based buffer on Windows Server 2022 (caused by `asyncio` / `socket`)
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Crash report
What happened?
On Windows Server 2022, when exiting a Python process, we sporadically get a dialog with the title "python.exe - System Error", which reads "The system detected an overrun of a stack-based buffer in this application. This overrun could potentially allow a malicious user to gain control of this application."
We do not get this error with Windows Server 2019.
The issue is very sporadically. Even with the following reproducers, we only experience the issue every 1,000 to 100,000 runs on our systems.
Our initial reproducer was:
import asyncio
async def f():
pass
asyncio.run(f())
We could narrow it down further to:
import socket
socket.socketpair()
(The issue does also occur if I close the sockets returned from socketpair.)
The issue can also be reproduced with the following snippet extracted from socket.socketpair():
import socket
l = socket.socket()
l.bind(("127.0.0.1",0))
l.listen()
c = socket.socket()
c.setblocking(False)
try:
c.connect(l.getsockname())
except BlockingIOError:
pass
Setting the socket to unblocking seems to be essential. I could not reproduce the issue without setting it to unblocking.
Further, calling os._exit() prevents the issue. I digged a little further and found that not calling WSACleanup() in os_cleanup() in socketmodule.c prevents the issue.
CPython versions tested on:
3.11, 3.12, 3.13, 3.14
Operating systems tested on:
Windows
Output from running 'python -VV' on the command line:
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 socketmodule.c 中的 os_cleanup() 开始,重点关注 WSACleanup() 调用。在 Windows Server 2022 上反复运行使用 socketpair() 或非阻塞 socket 的最小复现程序,并将行为与 Windows Server 2019 进行比较。完成标准是确定并修正 shutdown 路径,使 stack-buffer-overrun 对话框不再出现。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- networking, operating-systems
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100