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

pathlib.resolve() causes infinite loop on Windows #73265

Closed
GeorgMischler mannequin opened this issue Dec 26, 2016 · 5 comments
Closed

pathlib.resolve() causes infinite loop on Windows #73265

GeorgMischler mannequin opened this issue Dec 26, 2016 · 5 comments
Assignees
Labels
3.7 (EOL) end of life OS-windows stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@GeorgMischler
Copy link
Mannequin

GeorgMischler mannequin commented Dec 26, 2016

BPO 29079
Nosy @pfmoore, @pitrou, @tjguk, @zware, @serhiy-storchaka, @zooba
PRs
  • [Do Not Merge] Convert Misc/NEWS so that it is managed by towncrier #552
  • 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 = 'https://github.com/zooba'
    closed_at = <Date 2016-12-29.00:04:11.270>
    created_at = <Date 2016-12-26.20:46:14.262>
    labels = ['3.7', 'type-bug', 'library', 'OS-windows']
    title = 'pathlib.resolve() causes infinite loop on Windows'
    updated_at = <Date 2017-03-31.16:36:34.212>
    user = 'https://bugs.python.org/GeorgMischler'

    bugs.python.org fields:

    activity = <Date 2017-03-31.16:36:34.212>
    actor = 'dstufft'
    assignee = 'steve.dower'
    closed = True
    closed_date = <Date 2016-12-29.00:04:11.270>
    closer = 'steve.dower'
    components = ['Library (Lib)', 'Windows']
    creation = <Date 2016-12-26.20:46:14.262>
    creator = 'Georg Mischler'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 29079
    keywords = []
    message_count = 5.0
    messages = ['284045', '284048', '284217', '286760', '286806']
    nosy_count = 8.0
    nosy_names = ['paul.moore', 'pitrou', 'tim.golden', 'python-dev', 'zach.ware', 'serhiy.storchaka', 'steve.dower', 'Georg Mischler']
    pr_nums = ['552']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue29079'
    versions = ['Python 3.6', 'Python 3.7']

    @GeorgMischler
    Copy link
    Mannequin Author

    GeorgMischler mannequin commented Dec 26, 2016

    When pathlib.resolve() is invoked on Windows(10) with an absolute path including a non-existing drive, it gets caught in an infinite loop.

    To reproduce:
    Select a drive letter that doesn't exist on the system (in my case H:).
    Run the following line of code:
    pathlib.Path('h:\\').resolve()

    Expected result:
    returns the input string unchanged.

    Actual result:
    pathlib.resolve() ends up in an infinite loop, repeatedly calling _getfinalpathname() on the same string.

    @GeorgMischler GeorgMischler mannequin added 3.7 (EOL) end of life stdlib Python modules in the Lib dir OS-windows type-bug An unexpected behavior, bug, or error labels Dec 26, 2016
    @zooba
    Copy link
    Member

    zooba commented Dec 26, 2016

    We should break out of the "while True" loop in _WindowsFlavour.resolve when joining with ".." doesn't result in a different path.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Dec 29, 2016

    New changeset af8c8551ea45 by Steve Dower in branch '3.6':
    Issue bpo-29079: Prevent infinite loop in pathlib.resolve() on Windows
    https://hg.python.org/cpython/rev/af8c8551ea45

    New changeset 9de7bf6c60d2 by Steve Dower in branch 'default':
    Issue bpo-29079: Prevent infinite loop in pathlib.resolve() on Windows
    https://hg.python.org/cpython/rev/9de7bf6c60d2

    @zooba zooba closed this as completed Dec 29, 2016
    @zooba zooba self-assigned this Dec 29, 2016
    @serhiy-storchaka
    Copy link
    Member

    I'm not sure the fix is correct. os.path.dirname(s) can point to different place than os.path.abspath(os.path.join(s, os.pardir)) if the last component of s is "..", "." or a symbolic link.

    Would be nice to add tests.

    @zooba
    Copy link
    Member

    zooba commented Feb 2, 2017

    At the point this code is running, it doesn't matter. The path doesn't exist, so trimming irrelevant segments from it will just cause a few extra iterations through resolve until we clear out enough of the absent segments to find something that does exist.

    abspath just prepends the current working directory unless the path is rooted, so we essentially have unbounded concatenation of "\.." in that case.

    @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
    3.7 (EOL) end of life OS-windows stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants