python / python/cpython

Permission denied using mmap on Windows

Open
#99,871 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

3.15 extension-modules OS-windows type-feature
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Modules/mmapmodule.c around line 1531 and read the Windows mmap handling alongside the CreateFileMapping() and OpenFileMapping() documentation. Reproduce the server.py and client.py example on Windows 11. Done means the server can create the Global mapping and the client can open and read it without a permission error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.