Skip to content
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

Closed
DavidPritchard mannequin opened this issue Dec 19, 2012 · 8 comments
Closed

_fill_cache in _bootstrap.py crashes without directory execute permissions #60934

DavidPritchard mannequin opened this issue Dec 19, 2012 · 8 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@DavidPritchard
Copy link
Mannequin

DavidPritchard mannequin commented Dec 19, 2012

BPO 16730
Nosy @brettcannon, @jcea, @pitrou, @tiran, @meadori, @ericsnowcurrently
Files
  • _bootstrap.py.patch: diff patch to fix.
  • 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:

    assignee = None
    closed_at = <Date 2013-01-11.20:46:09.034>
    created_at = <Date 2012-12-19.14:55:01.344>
    labels = ['interpreter-core', 'type-bug']
    title = '_fill_cache in _bootstrap.py crashes without directory execute permissions'
    updated_at = <Date 2013-01-11.20:46:09.004>
    user = 'https://bugs.python.org/DavidPritchard'

    bugs.python.org fields:

    activity = <Date 2013-01-11.20:46:09.004>
    actor = 'brett.cannon'
    assignee = 'none'
    closed = True
    closed_date = <Date 2013-01-11.20:46:09.034>
    closer = 'brett.cannon'
    components = ['Interpreter Core']
    creation = <Date 2012-12-19.14:55:01.344>
    creator = 'David.Pritchard'
    dependencies = []
    files = ['28359']
    hgrepos = []
    issue_num = 16730
    keywords = ['patch']
    message_count = 8.0
    messages = ['177745', '177746', '177769', '177776', '178963', '178986', '179729', '179730']
    nosy_count = 8.0
    nosy_names = ['brett.cannon', 'jcea', 'pitrou', 'christian.heimes', 'meador.inge', 'python-dev', 'eric.snow', 'David.Pritchard']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue16730'
    versions = ['Python 3.3', 'Python 3.4']

    @DavidPritchard
    Copy link
    Mannequin Author

    DavidPritchard mannequin commented Dec 19, 2012

    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.

    @DavidPritchard DavidPritchard mannequin added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Dec 19, 2012
    @DavidPritchard
    Copy link
    Mannequin Author

    DavidPritchard mannequin commented Dec 19, 2012

    Sorry, in the main text of my message, "write permissions" should say directory execute permissions (permission to list contents of a directory)

    @ericsnowcurrently
    Copy link
    Member

    Patch looks good to me. Are there any other exceptions that might be included here?

    @brettcannon
    Copy link
    Member

    If Antoine can't think of any then I think there aren't any more. This does need a test, though.

    @brettcannon brettcannon added the type-bug An unexpected behavior, bug, or error label Dec 19, 2012
    @tiran
    Copy link
    Member

    tiran commented Jan 3, 2013

    NotADirectoryError is missing from the list of exception. The error can occur when the directory is removed and replaced by an ordinary file.

    @DavidPritchard
    Copy link
    Mannequin Author

    DavidPritchard mannequin commented Jan 3, 2013

    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
    (2) chmod a-rw+x on that directory
    (3) export PYTHONPATH=""
    (4) python3 from within that directory: should crash on loading

    Note, without step (3) the error does not occur. Alternatively, do (1), (2),

    (3') set PYTHONPATH to that -rw'ed directory
    (4') python3 from outside of that directory: should crash on loading

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 11, 2013

    New changeset 159967aa24a5 by Brett Cannon in branch '3.3':
    Issue bpo-16730: Don't raise an exception in
    http://hg.python.org/cpython/rev/159967aa24a5

    New changeset b94f308e9b47 by Brett Cannon in branch 'default':
    Merge from 3.3 for fix for issue bpo-16730
    http://hg.python.org/cpython/rev/b94f308e9b47

    @brettcannon
    Copy link
    Member

    Tests added for both the file and unreadable cases and the appropriate exceptions now caught. Thanks to everyone for helping with this!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants