[New-bugs-announce] [issue43810] os.path.abspath returns invalid path (resolves symbolic link)

Rene Visser report at bugs.python.org
Mon Apr 12 01:24:45 EDT 2021


New submission from Rene Visser <renevisser at gmail.com>:

According to the python documentation os.path.abspath() does *not* resolve symbolic links. This however does not always seem to be true causing an invalid path return by abspath. This could potentially be exploited to crash python applications.

Example for bug reproduction on a linux terminal:
1. create a sub-directory "bug_abspath"
2. enter the sub-dir "bug_abspath"
3. create a symbolic link "local_link" onto the current dir using: "ln -s . local_link"
4. open python session and import os and enter the following:
5. path_correct = os.path.abspath('./../bug_abspath')  # returns correct path
6. path_invalid = os.path.abspath('local_link/../bug_abspath')  # returns invalid path with wrongly resolved "local_link"

>From step 5 the correct/valid path is returned, from step 6 abspath returns an invalid path that is non-existing (contains non-existing "bug_abspath/bug_abspath" string. 
I consider this behavior incorrect and interpret it as a bug in the abspath routine which is not allowed to resolve the symbolic link "local_link".
(Note os.path.realpath works as expected but is unwanted by me).

Tested on
OS: linux ubuntu 20.04, CentOS 7.8
PY: python 3.7 and 3.8

Thanks for any help, best wishes, Rene

----------
components: IO
messages: 390818
nosy: rvisser
priority: normal
severity: normal
status: open
title: os.path.abspath returns invalid path (resolves symbolic link)
type: behavior
versions: Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43810>
_______________________________________


More information about the New-bugs-announce mailing list