Eryk Sun <eryk...@gmail.com> added the comment:

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

----------
components: +Library (Lib)
nosy: +Antoine d'Otreppe, eryksun -9001
stage:  -> needs patch
title: realpath of bytestr smb drive letters fail -> [Windows] 
ntpath.realpath() of bytes root directory may raise TypeError in some cases
versions: +Python 3.10

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue43847>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to