Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os: investigate dropping support for pre-long-path Windows #69853

Open
neild opened this issue Oct 11, 2024 · 3 comments
Open

os: investigate dropping support for pre-long-path Windows #69853

neild opened this issue Oct 11, 2024 · 3 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows

Comments

@neild
Copy link
Contributor

neild commented Oct 11, 2024

On Windows, the os package includes some trickery to enable support for long paths on older versions of Windows. The fixLongPath function rewrites longer paths to contain a \\?\ prefix, which "tells the Windows APIs to disable all string parsing and to send the string that follows it straight to the file system." (https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#win32-file-namespaces)

The \\?\ prefix can have effects other than just making a longer path work. For example, Mkdir(`\\?\c:\foo `) will create a directory "foo " with a trailing space, while Mkdir(`c:\foo `) will strip the space and create "foo".

Newer versions of Windows optionally support long paths directly. On Windows 10.0 with a build ID of 15063 and higher, we skip the \\?\ workaround: https://go.googlesource.com/go/+/refs/tags/go1.23.0/src/runtime/os_windows.go#450

Interestingly, the Windows documentation indicates that long paths should be supported on 10.0.1607 and higher
(https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry#enable-long-paths-in-windows-10-version-1607-and-later), and 1607 is build id 14393 (https://learn.microsoft.com/en-us/windows/release-health/release-information).

I don't know why we're checking for a build ID of 15063 instead of 14393.

https://go.dev/wiki/MinimumRequirements#windowswindows says that the supported Windows versions are Windows 10 and higher or Windows Server 2016 and higher.

I don't know what versions of Windows Server 2016 support long paths.

Do we still support any versions of Windows that don't have long path support? Can we just drop the \\?\ workaround entirely?

/cc @qmuntal

@seankhliao seankhliao added OS-Windows NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Oct 11, 2024
@ianlancetaylor
Copy link
Contributor

Perhaps related to #66560.

@qmuntal
Copy link
Contributor

qmuntal commented Oct 12, 2024

Yep, this proposal is the opposite of #66560. A summary of what I said in there:

  • Windows does not support enabling long path support at runtime. To do it right, one must embed a manifest to the binary stating long path support and also opt-in to long path support system-wide via a registry setting. See https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry#enable-long-paths-in-windows-10-version-1607-and-later for the exact steps to follow. Note that prepending \\?\ to the path is also a documented alternative.
  • Go uses an undocumented hack (modify the TEB) to enable long path support at runtime. It is the sole big framework that does so. If you use Python, C#, Node, Rust, etc., you should follow the official way to enable long path support.
  • The Windows security team at Microsoft opinion about Go's hack is that we shouldn't be doing it. It is not covered by the Windows back compat policy and any use of undocumented API should be treated as a security issue, as it will eventually result in unexpected behavior. They will not hesitate to break Go if there is any vulnerability that requires modifying how it enables long path support,
  • The Microsoft Go fork that my team maintains has removed this hack to be in compliance with the aforementioned policy.
  • I'm working with the Windows security team to find a way to enable long path support without having to modify the registry, just by using the embedded manifest, but the chances of this happening soon are quite low.

In a nutshell, I'm opposed to this proposal, it goes in the opposite direction of what I think we should be doing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

No branches or pull requests

5 participants