-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mmap lacks error handling (SEH) on Windows which can lead to interpreter crashes #118209
Comments
Posted this on the PR, but repeating here: One other possibility may be to protect |
On POSIX, the Is it premature to implement SEH or VEH support for this on Windows, given nothing similar is currently implemented on POSIX? |
Something has to be implemented first, and the likelihood of finding someone capable of doing both is pretty slim. I think we're best to implement one first, but in a way that's easily adapted to support other platforms (e.g. my |
…dule (pythonGH-118213) (cherry picked from commit e85e8de) Co-authored-by: Dobatymo <[email protected]>
…H-118213) (cherry picked from commit e85e8de) Co-authored-by: Dobatymo <[email protected]>
Thanks for the contribution! This is now merged into 3.13 for beta 2. If someone would like to add POSIX/signal support, please feel free, but let's do it on a new issue. Similarly with any additional operations that we can protect using SEH. |
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 aOSError: [Errno 22] Invalid argument
exception. Whereas doing the same usingmmap
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
cpython/Modules/mmapmodule.c
Lines 294 to 313 in 2584082
CPython versions tested on:
3.8
Operating systems tested on:
Windows
Output from running 'python -VV' on the command line:
No response
Linked PRs
The text was updated successfully, but these errors were encountered: