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.

Author eryksun
Recipients Antoine d'Otreppe, eryksun, paul.moore, steve.dower, tim.golden, zach.ware
Date 2021-04-15.07:15:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1618470950.91.0.73100161618.issue43847@roundup.psfhosted.org>
In-reply-to
Content
In ntpath._getfinalpathname_nonstrict(), `tail` should be initialized to `path[:0]`. 

Currently `tail` is initialized to the empty string value ''. If an error occurs that's allowed and `path` is a root directory that's passed as bytes, then joining `path + tail` will fail if `tail` still has its initial value. 

To reproduce this issue, create a substitute drive for a directory that grants no access. For example:

    import os
    os.mkdir('spam')
    os.system('icacls spam /inheritance:r')
    os.system('subst N: spam')

    >>> os.path.realpath(b'N:/')
    Traceback (most recent call last):
      File "C:\Program Files\Python39\lib\ntpath.py", line 647, in realpath
        path = _getfinalpathname(path)
    PermissionError: [WinError 5] Access is denied: b'N:\\'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "C:\Program Files\Python39\lib\ntpath.py", line 601, in _getfinalpathname_nonstrict
        path = _getfinalpathname(path)
    PermissionError: [WinError 5] Access is denied: b'N:\\'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Program Files\Python39\lib\ntpath.py", line 651, in realpath
        path = _getfinalpathname_nonstrict(path)
      File "C:\Program Files\Python39\lib\ntpath.py", line 621, in _getfinalpathname_nonstrict
        return path + tail
    TypeError: can't concat str to bytes
History
Date User Action Args
2021-04-15 07:15:50eryksunsetrecipients: + eryksun, paul.moore, tim.golden, Antoine d'Otreppe, zach.ware, steve.dower
2021-04-15 07:15:50eryksunsetmessageid: <1618470950.91.0.73100161618.issue43847@roundup.psfhosted.org>
2021-04-15 07:15:50eryksunlinkissue43847 messages
2021-04-15 07:15:50eryksuncreate