python / python/cpython

SIGBUS: writing to `mmap`ed device beyond file size

Open
#119,817 8 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

extension-modules type-crash
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

Crash report

What happened?
# DEV=/dev/foo
# blockdev --getsize64 $DEV
1048576
# tail $DEV
# python3.12 bug.py
Bus error (core dumped)
# tail $DEV
hell#
from mmap import mmap

with open('/dev/foo', 'r+b') as file:
    m = mmap(file.fileno(), 1024 ** 2 + 1)

m.seek(1024 ** 2 - 4)

for b in b'hello world!':
    m.write(bytes([b]))

I hope you don't mind my reference to Madagascar

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Output from running 'python -VV' on the command line:

Python 3.12.3 (main, Apr 27 2024, 19:00:21) [GCC 11.4.0]

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 by running the provided bug.py reproduction on Linux with a device whose size matches the report, then inspect the mmap write behavior and existing mmap tests. Determine the expected handling when the mapping extends beyond the device size; done means the reproduction is covered by a regression test and no longer crashes unexpectedly.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.