python / python/cpython

Permission denied using mmap on Windows

Đang mở
#99,871 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

3.15 extension-modules OS-windows type-feature
Ngôn ngữ chính
Python
Star
77.2k
Fork
36k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

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)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu trong Modules/mmapmodule.c quanh dòng 1531 và đọc phần xử lý mmap trên Windows cùng với tài liệu về CreateFileMapping() và OpenFileMapping(). Tái hiện ví dụ server.py và client.py trên Windows 11. Hoàn tất khi server có thể tạo mapping Global và client có thể mở, đọc nó mà không gặp lỗi quyền.

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
operating-systems
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 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
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.