Closed as duplicate
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.