Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
gh-118209: Add structured exception handling to mmap module#118213
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
4013627648413471218d2cd4b1fccb1ef19448fa90ba96163f97d2137983869c0bd57b92f4bf0364d84604dc2d90654f9bd3661ff30aa64bb809ce9e907e6dd1ad0ab2ca440df7c356c0d701086f1f72605e8ca029b12bf59e8c4e4f610a5aa2b41d11fa04af02c83a8533af56aeaa329737f2212fb561880a9c0File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,6 +3,7 @@ | ||
| ) | ||
| from test.support.import_helper import import_module | ||
| from test.support.os_helper import TESTFN, unlink | ||
| from test.support.script_helper import assert_python_ok | ||
| import unittest | ||
| import errno | ||
| import os | ||
| @@ -12,6 +13,7 @@ | ||
| import socket | ||
| import string | ||
| import sys | ||
| import textwrap | ||
| import weakref | ||
| # Skip test if we can't import mmap. | ||
| @@ -1058,6 +1060,81 @@ def __exit__(self, exc_type, exc_value, traceback): | ||
| with self.assertRaisesRegex(ValueError, "mmap closed or invalid"): | ||
| m.write_byte(X()) | ||
| @unittest.skipUnless(os.name == 'nt', 'requires Windows') | ||
| @unittest.skipUnless(hasattr(mmap.mmap, '_protect'), 'test needs debug build') | ||
| def test_access_violations(self): | ||
| from test.support.os_helper import TESTFN | ||
| code = textwrap.dedent(""" | ||
| import faulthandler | ||
| import mmap | ||
| import os | ||
| import sys | ||
| from contextlib import suppress | ||
| # Prevent logging access violations to stderr. | ||
| faulthandler.disable() | ||
Dobatymo marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| PAGESIZE = mmap.PAGESIZE | ||
| PAGE_NOACCESS = 0x01 | ||
| with open(sys.argv[1], 'bw+') as f: | ||
| f.write(b'A'* PAGESIZE) | ||
| f.flush() | ||
| m = mmap.mmap(f.fileno(), PAGESIZE) | ||
| m._protect(PAGE_NOACCESS, 0, PAGESIZE) | ||
| with suppress(OSError): | ||
zooba marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| m.read(PAGESIZE) | ||
| assert False, 'mmap.read() did not raise' | ||
| with suppress(OSError): | ||
| m.read_byte() | ||
| assert False, 'mmap.read_byte() did not raise' | ||
| with suppress(OSError): | ||
| m.readline() | ||
| assert False, 'mmap.readline() did not raise' | ||
| with suppress(OSError): | ||
| m.write(b'A'* PAGESIZE) | ||
| assert False, 'mmap.write() did not raise' | ||
| with suppress(OSError): | ||
| m.write_byte(0) | ||
| assert False, 'mmap.write_byte() did not raise' | ||
| with suppress(OSError): | ||
| m[0] # test mmap_subscript | ||
| assert False, 'mmap.__getitem__() did not raise' | ||
| with suppress(OSError): | ||
| m[0:10] # test mmap_subscript | ||
| assert False, 'mmap.__getitem__() did not raise' | ||
| with suppress(OSError): | ||
| m[0:10:2] # test mmap_subscript | ||
| assert False, 'mmap.__getitem__() did not raise' | ||
| with suppress(OSError): | ||
| m[0] = 1 | ||
| assert False, 'mmap.__setitem__() did not raise' | ||
| with suppress(OSError): | ||
| m[0:10] = b'A'* 10 | ||
| assert False, 'mmap.__setitem__() did not raise' | ||
| with suppress(OSError): | ||
| m[0:10:2] = b'A'* 5 | ||
| assert False, 'mmap.__setitem__() did not raise' | ||
| with suppress(OSError): | ||
| m.move(0, 10, 1) | ||
| assert False, 'mmap.move() did not raise' | ||
| with suppress(OSError): | ||
| list(m) # test mmap_item | ||
| assert False, 'mmap.__getitem__() did not raise' | ||
| with suppress(OSError): | ||
| m.find(b'A') | ||
| assert False, 'mmap.find() did not raise' | ||
| with suppress(OSError): | ||
| m.rfind(b'A') | ||
| assert False, 'mmap.rfind() did not raise' | ||
| """) | ||
| rt, stdout, stderr = assert_python_ok("-c", code, TESTFN) | ||
| self.assertEqual(stdout.strip(), b'') | ||
| self.assertEqual(stderr.strip(), b'') | ||
| class LargeMmapTests(unittest.TestCase): | ||
| def setUp(self): | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Avoid crashing in :mod:`mmap` on Windows when the mapped memory is inaccessible | ||
| due to file system errors or access violations. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.