Description
Crash report
What happened?
mmap
reads and writes require structured exception handling (SEH) for correct handling of errors (like hardware read issues, or disk full write issues) on Windows. See https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-mapviewoffile#remarks for a description of the possible exceptions and https://learn.microsoft.com/en-us/windows/win32/memory/reading-and-writing-from-a-file-view for how to handle them.
I found this issue when trying to read a file from a corrupt hdd. A normal open().read()
would raise a OSError: [Errno 22] Invalid argument
exception. Whereas doing the same using mmap
crashes the interpreter.
I only tested on Windows 7 and Python 3.8, but from looking at the Microsoft docs and the Python source code, this issue should exist for all Windows versions and the latest Python source. (I don't have access to the broken file from a newer machine)
I think there is nothing here which guards against these errors
Lines 294 to 313 in 2584082
with open(path, "rb") as fp:
with mmap.mmap(fp.fileno(), 0, access=mmap.ACCESS_READ) as fr:
fr.read(1024*8) # this crashes when `path` is on a corrupt hdd for example.
CPython versions tested on:
3.8
Operating systems tested on:
Windows
Output from running 'python -VV' on the command line:
No response