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

Skip to content

Wrong paths from nt._getfinalpathname with DOS device selectors in the CWD #112563

Open
@CarlitoGil

Description

@CarlitoGil

Bug report

Bug description:

In Windows if the CWD has a device selector \\.\ or \\?\ any function dependent on nt._getfullpathname may change the meaning of the path.

import os
import ntpath
os.chdir('\\\\?\\C:\\') # any path with a device selector
print(ntpath.abspath('\\')) # NOTE: single slash character

That code will print \\
and I mean 2 slashes, not an escaped one.

So if you use:

print(ntpath.abspath('\\Some\\Path')) # single slash before each component

The result is \\Some\Path.
That is an UNC network share, not a file named Path a couple of levels down from the root of the volume.
Perhaps there are security concerns there.

And if the CWD is a volume root, or drive device root, then:

os.chdir('\\\\.\\C:\\') # or \\?\Volume{GUID}\
print(ntpath.abspath('.')) # current directory

That will show \\.\C:
which is a device block, which means os.scandir would raise an error with that path.

CPython versions tested on:

3.12

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-windowstype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions