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

Path.mkdir can get into a recursive error loop #73602

Closed
DanBuchoff mannequin opened this issue Feb 1, 2017 · 7 comments
Closed

Path.mkdir can get into a recursive error loop #73602

DanBuchoff mannequin opened this issue Feb 1, 2017 · 7 comments
Assignees
Labels
3.7 only security fixes OS-windows stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@DanBuchoff
Copy link
Mannequin

DanBuchoff mannequin commented Feb 1, 2017

BPO 29416
Nosy @pfmoore, @tjguk, @zware, @eryksun, @zooba

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 2017-11-09.18:03:53.736>
created_at = <Date 2017-02-01.22:46:32.944>
labels = ['3.7', 'type-bug', 'library', 'OS-windows']
title = 'Path.mkdir can get into a recursive error loop'
updated_at = <Date 2017-11-09.18:03:53.735>
user = 'https://bugs.python.org/DanBuchoff'

bugs.python.org fields:

activity = <Date 2017-11-09.18:03:53.735>
actor = 'serhiy.storchaka'
assignee = 'steve.dower'
closed = True
closed_date = <Date 2017-11-09.18:03:53.736>
closer = 'serhiy.storchaka'
components = ['Library (Lib)', 'Windows']
creation = <Date 2017-02-01.22:46:32.944>
creator = 'Dan Buchoff'
dependencies = []
files = []
hgrepos = []
issue_num = 29416
keywords = []
message_count = 7.0
messages = ['286717', '286723', '286734', '286999', '287000', '287001', '287002']
nosy_count = 7.0
nosy_names = ['paul.moore', 'tim.golden', 'python-dev', 'zach.ware', 'eryksun', 'steve.dower', 'Dan Buchoff']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue29416'
versions = ['Python 3.5', 'Python 3.6', 'Python 3.7']

@DanBuchoff
Copy link
Mannequin Author

DanBuchoff mannequin commented Feb 1, 2017

If a path has a non-existent anchor, Path.mkdir can get into a RecursionError as it tries to recursively create the parent. I expect a more sane error.

This is readily reproducible in Windows with Path('Z:').mkdir(parents=True)

Example execution:

Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pathlib import Path
>>> Path('Z:').mkdir(parents=True)
Traceback (most recent call last):
  File "C:\Python36\lib\pathlib.py", line 1231, in mkdir
    self._accessor.mkdir(self, mode)
  File "C:\Python36\lib\pathlib.py", line 388, in wrapped
    return strfunc(str(pathobj), *args)
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'Z:'

During handling of the above exception, another exception occurred:

...

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python36\lib\pathlib.py", line 1238, in mkdir
    self.parent.mkdir(parents=True)
  File "C:\Python36\lib\pathlib.py", line 1238, in mkdir
    self.parent.mkdir(parents=True)
  File "C:\Python36\lib\pathlib.py", line 1238, in mkdir
    self.parent.mkdir(parents=True)
  [Previous line repeated 989 more times]
  File "C:\Python36\lib\pathlib.py", line 1231, in mkdir
    self._accessor.mkdir(self, mode)
  File "C:\Python36\lib\pathlib.py", line 388, in wrapped
    return strfunc(str(pathobj), *args)
RecursionError: maximum recursion depth exceeded

@DanBuchoff DanBuchoff mannequin added stdlib Python modules in the Lib dir OS-windows type-bug An unexpected behavior, bug, or error labels Feb 1, 2017
@zooba
Copy link
Member

zooba commented Feb 2, 2017

Might be worth checking if this is resolved with bpo-29079, which is already in for 3.6.1.

@eryksun
Copy link
Contributor

eryksun commented Feb 2, 2017

This case is similar to bpo-29079. It should only attempt to make the parent to handle ENOENT if self and self.parent aren't equal. Here's the snippet from Path.mkdir:

try:
    self._accessor.mkdir(self, mode)
except FileExistsError:
    if not exist_ok or not self.is_dir():
        raise
except OSError as e:
    if e.errno != ENOENT:
        raise
    self.parent.mkdir(parents=True)
    self._accessor.mkdir(self, mode)

@eryksun eryksun added the 3.7 only security fixes label Feb 2, 2017
@python-dev
Copy link
Mannequin

python-dev mannequin commented Feb 4, 2017

New changeset 8061d0967988 by Steve Dower in branch '3.5':
Issue bpo-29416: Prevent infinite loop in pathlib.Path.mkdir
https://hg.python.org/cpython/rev/8061d0967988

New changeset 3de58a54ed98 by Steve Dower in branch '3.6':
Issue bpo-29416: Prevent infinite loop in pathlib.Path.mkdir
https://hg.python.org/cpython/rev/3de58a54ed98

New changeset 09c018897fb3 by Steve Dower in branch 'default':
Issue bpo-29416: Prevent infinite loop in pathlib.Path.mkdir
https://hg.python.org/cpython/rev/09c018897fb3

@zooba zooba self-assigned this Feb 4, 2017
@python-dev
Copy link
Mannequin

python-dev mannequin commented Feb 4, 2017

New changeset 661c40ba59855ebe4967424fcabd41be6f799137 by Steve Dower in branch 'master':
Issue bpo-29416: Prevent infinite loop in pathlib.Path.mkdir
661c40b

New changeset 77da63372461ddeb82dbfdef86e702e43e24e1da by Steve Dower in branch 'master':
Issue bpo-29416: Prevent infinite loop in pathlib.Path.mkdir
77da633

New changeset c05ffe646dc009c01365db917f0ca6b738fda69b by Steve Dower in branch 'master':
Issue bpo-29416: Prevent infinite loop in pathlib.Path.mkdir
c05ffe6

@python-dev
Copy link
Mannequin

python-dev mannequin commented Feb 4, 2017

New changeset 661c40ba59855ebe4967424fcabd41be6f799137 by Steve Dower in branch '3.6':
Issue bpo-29416: Prevent infinite loop in pathlib.Path.mkdir
661c40b

New changeset 77da63372461ddeb82dbfdef86e702e43e24e1da by Steve Dower in branch '3.6':
Issue bpo-29416: Prevent infinite loop in pathlib.Path.mkdir
77da633

@python-dev
Copy link
Mannequin

python-dev mannequin commented Feb 4, 2017

New changeset 661c40ba59855ebe4967424fcabd41be6f799137 by Steve Dower in branch '3.5':
Issue bpo-29416: Prevent infinite loop in pathlib.Path.mkdir
661c40b

@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 only security fixes 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

3 participants