python / python/cpython

Permission denied using mmap on Windows

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

還沒有人認領這個 Issue。

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

描述

Bug report

I have a Windows service that creates a memory mapped file using the global scope and a client that reads the global scope. The problem is that the current implementation calls CreateFileMapping() instead of OpenFileMapping(). So when the client tries to connect the global scope, its throws a permission error.

The expected behavior is: Only the server has the permission the create a global memory mapped file and any client can read the created memory mapped file.

Here is a sample code:

server.py

from mmap import mmap
from pickle import load, dump


mm = mmap(-1, 32, tagname=r'Global\test')

last_request_id = None
while True:
    mm.seek(0)
    try:
        request_id = int(load(mm))
        if request_id != last_request_id:
            last_request_id = request_id
            print(request_id)
        
    except Exception:
        pass

client.py

from mmap import mmap
from pickle import dump


with mmap(-1, 32, tagname='Global\test') as mm:
    request_id = 1
    dump(request_id, mm)

Your environment

  • CPython versions tested on: 3.11
  • Operating system and architecture: Windows 11 - Version 22H2 (OS Build 22621.819)

貢獻指南

開啟貢獻指南

從這裡開始

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

研究方向

從 Modules/mmapmodule.c 的第 1531 行附近開始,搭配 CreateFileMapping() 和 OpenFileMapping() 的文件閱讀 Windows mmap 處理。在 Windows 11 上重現 server.py 和 client.py 範例。完成的標準是 server 可以建立 Global 對映,而 client 可以在沒有權限錯誤的情況下開啟並讀取它。

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

評估

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

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

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