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=Noneclosed_at=Nonecreated_at=<Date2021-10-21.22:21:02.146>labels= ['library', '3.9', 'type-crash']
title='shutil.rmtree and os.walk are implemented using recursion, fail on deep hierarchies'updated_at=<Date2021-10-21.22:21:02.146>user='https://bugs.python.org/AlexanderPatrakov'
It is possible to create deep directory hierarchies that cannot be removed via shutil.rmtree or walked via os.walk, because these functions exceed the interpreter recursion limit. This may have security implications for web services (e.g. various webdisks) that have to clean up user-created mess or walk through it.
[aep@aep-haswell ~]$ mkdir /tmp/badstuff
[aep@aep-haswell ~]$ cd /tmp/badstuff
[aep@aep-haswell badstuff]$ for x in `seq 2048` ; do mkdir $x ; cd $x ; done
[aep@aep-haswell 103]$ cd
[aep@aep-haswell ~]$ python
Python 3.9.7 (default, Oct 10 2021, 15:13:22)
[GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import shutil
>>> shutil.rmtree('/tmp/badstuff')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.9/shutil.py", line 726, in rmtree
_rmtree_safe_fd(fd, path, onerror)
File "/usr/lib/python3.9/shutil.py", line 663, in _rmtree_safe_fd
_rmtree_safe_fd(dirfd, fullname, onerror)
File "/usr/lib/python3.9/shutil.py", line 663, in _rmtree_safe_fd
_rmtree_safe_fd(dirfd, fullname, onerror)
File "/usr/lib/python3.9/shutil.py", line 663, in _rmtree_safe_fd
_rmtree_safe_fd(dirfd, fullname, onerror)
[Previous line repeated 992 more times]
File "/usr/lib/python3.9/shutil.py", line 642, in _rmtree_safe_fd
fullname = os.path.join(path, entry.name)
File "/usr/lib/python3.9/posixpath.py", line 77, in join
sep = _get_sep(a)
File "/usr/lib/python3.9/posixpath.py", line 42, in _get_sep
if isinstance(path, bytes):
RecursionError: maximum recursion depth exceeded while calling a Python object
>>> import os
>>> list(os.walk('/tmp/badstuff'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.9/os.py", line 418, in _walk
yield from _walk(new_path, topdown, onerror, followlinks)
File "/usr/lib/python3.9/os.py", line 418, in _walk
yield from _walk(new_path, topdown, onerror, followlinks)
File "/usr/lib/python3.9/os.py", line 418, in _walk
yield from _walk(new_path, topdown, onerror, followlinks)
[Previous line repeated 993 more times]
File "/usr/lib/python3.9/os.py", line 412, in _walk
new_path = join(top, dirname)
File "/usr/lib/python3.9/posixpath.py", line 77, in join
sep = _get_sep(a)
File "/usr/lib/python3.9/posixpath.py", line 42, in _get_sep
if isinstance(path, bytes):
RecursionError: maximum recursion depth exceeded while calling a Python object
>>>
Activity
AlexanderPatrakov commented on Oct 21, 2021
It is possible to create deep directory hierarchies that cannot be removed via shutil.rmtree or walked via os.walk, because these functions exceed the interpreter recursion limit. This may have security implications for web services (e.g. various webdisks) that have to clean up user-created mess or walk through it.
pythongh-89727: Fix os.walk RecursionError on deep trees
pythongh-89727: Fix os.walk RecursionError on deep trees
barneygale commented on Nov 27, 2022
This also affects pathlib.Path.walk()
pythongh-89727: Fix os.walk RecursionError on deep trees
pythongh-89727: Fix os.walk RecursionError on deep trees
Merge branch 'main' into pythongh-89727/fix-pathlib.Path.walk-recursi…
101 remaining items
GH-89727: Fix `shutil.rmtree()` recursion error on deep trees (#119808)
pythonGH-89727: Fix `shutil.rmtree()` recursion error on deep trees (p…
pythonGH-89727: Fix `shutil.rmtree()` recursion error on deep trees (p…
[3.12] pythonGH-89727: Fix `shutil.rmtree()` recursion error on deep …
[3.13] GH-89727: Fix `shutil.rmtree()` recursion error on deep trees (G…
[3.12] GH-89727: Fix `shutil.rmtree()` recursion error on deep trees (G…
pythonGH-89727: Fix `shutil.rmtree()` recursion error on deep trees (p…
pythonGH-89727: Partially fix `shutil.rmtree()` recursion error on de…
pythonGH-89727: Fix `os.fwalk()` recursion error on deep trees (pytho…
pythonGH-89727: Fix FD leak on `os.fwalk()` generator finalization. (p…
pythonGH-89727: Fix `shutil.rmtree()` recursion error on deep trees (p…
pythonGH-89727: Partially fix `shutil.rmtree()` recursion error on de…
pythonGH-89727: Fix `os.fwalk()` recursion error on deep trees (pytho…
pythonGH-89727: Fix FD leak on `os.fwalk()` generator finalization. (p…
pythonGH-89727: Fix `shutil.rmtree()` recursion error on deep trees (p…