-
-
Notifications
You must be signed in to change notification settings - Fork 29.1k
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
_fill_cache in _bootstrap.py crashes without directory execute permissions #60934
Comments
In importlib/_bootstrap.py, there is a function _fill_cache which crashes when you try to run Python in any environment that is so restricted that write permissions are not allowed. You get a trace like: Traceback (most recent call last):
In line:
[the import statement]
File "<frozen importlib._bootstrap>", line 1558, in _find_and_load
File "<frozen importlib._bootstrap>", line 1516, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1470, in _find_module
File "<frozen importlib._bootstrap>", line 1305, in find_module
File "<frozen importlib._bootstrap>", line 1284, in _get_loader
File "<frozen importlib._bootstrap>", line 1356, in find_loader
File "<frozen importlib._bootstrap>", line 1392, in _fill_cache
PermissionError: [Errno 13] Permission denied: '[the directory name]' This was not an issue when I was using Python 3.2 and I suspect it has to do with the OS error refactoring. I believe it can be fixed with a two-line patch, attached. (Sorry if it is the wrong format, it's the first one I've submitted.) The patch simply treats the case of PermissionError the same was as it does when there is a FileNotFoundError. I've tested the patch and it fixes the problem. |
Sorry, in the main text of my message, "write permissions" should say directory execute permissions (permission to list contents of a directory) |
Patch looks good to me. Are there any other exceptions that might be included here? |
If Antoine can't think of any then I think there aren't any more. This does need a test, though. |
NotADirectoryError is missing from the list of exception. The error can occur when the directory is removed and replaced by an ordinary file. |
Here's an example where Python 3.3.0 crashes, but where the patched code works. I have only been able to trigger the bug when PYTHONPATH is set (even if to an empty value). (1) create a directory Note, without step (3) the error does not occur. Alternatively, do (1), (2), (3') set PYTHONPATH to that -rw'ed directory |
New changeset 159967aa24a5 by Brett Cannon in branch '3.3': New changeset b94f308e9b47 by Brett Cannon in branch 'default': |
Tests added for both the file and unreadable cases and the appropriate exceptions now caught. Thanks to everyone for helping with this! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: