Thanks to visit codestin.com
Credit goes to github.com

Skip to content

os.path.realpath() RecursionError #128098

Closed as duplicate
Closed as duplicate
@jwilk

Description

@jwilk

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

No one assigned

    Labels

    3.12only security fixes3.13bugs and security fixes3.14bugs and security fixesextension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions