classification
Title: pathlib.resolve() causes infinite loop on Windows
Type: behavior Stage: resolved
Components: Library (Lib), Windows Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: steve.dower Nosy List: Georg Mischler, paul.moore, pitrou, python-dev, serhiy.storchaka, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2016-12-26 20:46 by Georg Mischler, last changed 2017-03-31 16:36 by dstufft. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 552 closed dstufft, 2017-03-31 16:36
Messages (5)
msg284045 - (view) Author: Georg Mischler (Georg Mischler) Date: 2016-12-26 20:46
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.
msg284048 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2016-12-26 21:41
We should break out of the "while True" loop in _WindowsFlavour.resolve when joining with ".." doesn't result in a different path.
msg284217 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-12-29 00:03
New changeset af8c8551ea45 by Steve Dower in branch '3.6':
Issue #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 #29079: Prevent infinite loop in pathlib.resolve() on Windows
https://hg.python.org/cpython/rev/9de7bf6c60d2
msg286760 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-02-02 10:21
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.
msg286806 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2017-02-02 16:30
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.
History
Date User Action Args
2017-03-31 16:36:34dstufftsetpull_requests: + pull_request1070
2017-02-02 16:30:53steve.dowersetmessages: + msg286806
2017-02-02 10:21:11serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg286760
2016-12-29 00:04:11steve.dowersetstatus: open -> closed
assignee: steve.dower
resolution: fixed
stage: needs patch -> resolved
2016-12-29 00:03:58python-devsetnosy: + python-dev
messages: + msg284217
2016-12-26 21:41:08steve.dowersetstage: needs patch
2016-12-26 21:41:00steve.dowersetmessages: + msg284048
2016-12-26 21:02:29serhiy.storchakasetnosy: + pitrou
2016-12-26 20:46:14Georg Mischlercreate