This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: os.path.realpath can't handle symlink loops
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: akuchling Nosy List: akuchling, barneygale, brett.cannon, loewis
Priority: high Keywords:

Created on 2004-04-05 20:59 by akuchling, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
posixpath.patch akuchling, 2004-06-05 18:58 Patch fixing os.path.realpath
Pull Requests
URL Status Linked Edit
PR 25264 barneygale, 2021-04-08 02:12
Messages (5)
msg20433 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2004-04-05 20:59
Create a symlink pointing to itself:

ln -s infinite infinite

Run os.path.realpath() on it, and it recurses
infinitely (until the stack limit is hit):

>>> import os
>>> os.path.realpath('/home/amk/infinite')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.3/", line 416, in
    return realpath(newpath)

os.path.realpath() should be fixed; /home/amk/infinite
is a perfectly good path, though it can't be followed.
msg20434 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2004-06-05 18:58
Logged In: YES 

Patch attached; review requested.
msg20435 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2004-07-10 22:59
Logged In: YES 

Applied as rev. 1.67 in 2.4a2 and rev. in 2.3.5 with only minor 
msg20436 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2004-08-02 10:20
Logged In: YES 

The code that has been committed is incorrect if the link to
be resolved is relative.  _resolve_link uses abspath to
determine whether the link is absolute. This function
returns an absolute path (possibly using getcwd); the
function that should have been used is isabs().
msg20437 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2004-08-03 12:15
Logged In: YES 

Fixed in 2.3-maint and on the trunk.
Date User Action Args
2022-04-11 14:56:03adminsetgithub: 40123
2021-04-08 02:12:01barneygalesetnosy: + barneygale

pull_requests: + pull_request24006
2004-04-05 20:59:41akuchlingcreate