Skip to content

std::fs::canonicalize uses GetFinalPathNameByHandleW, which can fail #79449

Closed as not planned
@Dwedit

Description

@Dwedit

I was just testing out the Win32 function GetFinalPathNameByHandleW, and saw a case where it failed to work.

Steps to reproduce:

  • Install OSFMount (Passmark)
  • Mount a Disk Image (I used a NTFS image file, mounted as drive X)
  • Use CreateFileW on a file on the disk image (my path: "X:/flash Movies/11-29-04-thanksgiving.swf")
  • Call GetFinalPathNameByHandleW on that handle, using FILE_NAME_NORMALIZED

Function returns 0 instead of returning a path name, and GetLastError returns 1 (ERROR_INVALID_FUNCTION).

However, if I call GetFinalPathNameByHandleW using VOLUME_NAME_NT, I get something: "\Device\OSFMDisk0\Flash Movies\11-29-04-thanksgiving.swf", but this path isn't usable with CreateFileW.

There are alternative ways to canonicalize a filename on Win32:
PathCanonicalizeW is the traditional way to do it, works on Windows 2000 and later, but it is limited to 260 character filenames, and is marked as deprecated by Microsoft.
PathCchCanonicalizeEx is the replacement function since Windows 8, and is unavailable in Windows 7 and earlier, but does support very long path names.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`C-bugCategory: This is a bug.O-windowsOperating system: WindowsT-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions