[New-bugs-announce] [issue40720] accessing mmap of file that is overwritten causes bus error

Marten H. van Kerkwijk report at bugs.python.org
Thu May 21 17:32:53 EDT 2020


New submission from Marten H. van Kerkwijk <mhvk at astro.utoronto.ca>:

While debugging a strange failure with tests and np.memmap, I realized that the following direct use of mmap reliably leads to a bus error. Here, obviously mmap'ing a file, closing it, opening the file for writing but not writing anything, and then again accessing the mmap is not something one should do (but a test case did it anyway), but it would nevertheless be nice to avoid a crash!
```
import mmap


with open('test.dat', 'wb') as fh:
    fh.write(b'abcdefghijklmnopqrstuvwxyz')


with open('test.dat', 'rb') as fh:
    mm = mmap.mmap(fh.fileno(), 0, access=mmap.ACCESS_READ)


with open('test.dat', 'wb') as fh:
    pass  # Note: if something is written, then I get no bus error.


mm[2]
```

----------
components: Library (Lib)
messages: 369543
nosy: mhvk
priority: normal
severity: normal
status: open
title: accessing mmap of file that is overwritten causes bus error
type: crash
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40720>
_______________________________________


More information about the New-bugs-announce mailing list