-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Closed as duplicate
Labels
3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
os.path.realpath()
attempts to detect symlink loops, but this is not bulletproof;
it's possible to make it fall into infinite recursion.
Reproducer:
import os
import tempfile
with tempfile.TemporaryDirectory() as tmpdir:
os.chdir(tmpdir)
os.symlink('../' * (1 + tmpdir.count('/')) + f'{tmpdir}/d', 'd')
os.path.realpath('d')
Traceback:
Traceback (most recent call last):
File ".../recursiverealpath.py", line 7, in <module>
os.path.realpath('d')
File "<frozen posixpath>", line 427, in realpath
File "<frozen posixpath>", line 487, in _joinrealpath
File "<frozen posixpath>", line 487, in _joinrealpath
File "<frozen posixpath>", line 487, in _joinrealpath
[Previous line repeated 993 more times]
File "<frozen posixpath>", line 442, in _joinrealpath
File "<frozen posixpath>", line 63, in isabs
RecursionError: maximum recursion depth exceeded
Tested with Python 3.12.8.
Metadata
Metadata
Assignees
Labels
3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error