Issue 29079: pathlib.resolve() causes infinite loop on Windows (original) (raw)

This issue has been migrated to GitHub: https://github.com/python/cpython/issues/73265

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 2022-04-11 14:58 by admin. 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
2022-04-11 14:58:41 admin set github: 73265
2017-03-31 16:36:34 dstufft set pull_requests: + <pull%5Frequest1070>
2017-02-02 16:30:53 steve.dower set messages: +
2017-02-02 10:21:11 serhiy.storchaka set nosy: + serhiy.storchakamessages: +
2016-12-29 00:04:11 steve.dower set status: open -> closedassignee: steve.dowerresolution: fixedstage: needs patch -> resolved
2016-12-29 00:03:58 python-dev set nosy: + python-devmessages: +
2016-12-26 21:41:08 steve.dower set stage: needs patch
2016-12-26 21:41:00 steve.dower set messages: +
2016-12-26 21:02:29 serhiy.storchaka set nosy: + pitrou
2016-12-26 20:46:14 Georg Mischler create