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

curl_multibyte: support Windows paths longer than MAX_PATH #13522

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jay
Copy link
Member

@jay jay commented May 3, 2024

  • Add a helper function for the Windows file wrapper functions that will normalize a long path (or a filename in a long path) and add the prefix \\?\ so that Windows will access the file.

Prior to this change if a filename (when normalized internally by Windows to its full path) or a path was longer than MAX_PATH (260) then Windows would not open the path, unless it was already normalized by the user and had the \\?\ prefix prepended.

The \\?\ prefix could not be passed to file:// so for example something like file://c:/foo/bar/filename255chars could not be opened prior to this change.

There's some code in tool_doswin that will need to be modified as well to further remove MAX_PATH (aka PATH_MAX) limitation.

Ref: #8361
Ref: #13512
Ref: https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats
Ref: https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation

Closes #xxxx

lib/curl_multibyte.c Outdated Show resolved Hide resolved
lib/curl_multibyte.c Outdated Show resolved Hide resolved
@bagder
Copy link
Member

bagder commented Jul 1, 2024

Merge conflicts. Any plans to move forward on this?

@nmoinvaz
Copy link
Contributor

nmoinvaz commented Jul 2, 2024

It is still necessary for our use case. @jay can you take a look at the conflicts?

@jay
Copy link
Member Author

jay commented Jul 19, 2024

I fixed the conflicts. Also I reversed and took @nmoinvaz's suggestion to use 'goto cleanup' instead of 'goto error' to eliminate any confusion in the logic.

Though I don't foresee this PR causing any problems I'm going to wait until the next feature window to land it.

- Add a helper function for the Windows file wrapper functions that will
  normalize a long path (or a filename in a long path) and add the
  prefix `\\?\` so that Windows will access the file.

Prior to this change if a filename (when normalized internally by
Windows to its full path) or a path was longer than MAX_PATH (260) then
Windows would not open the path, unless it was already normalized by the
user and had the `\\?\` prefix prepended.

The `\\?\` prefix could not be passed to file:// so for example
something like file://c:/foo/bar/filename255chars could not be opened
prior to this change.

There's some code in tool_doswin that will need to be modified as well
to further remove MAX_PATH (aka PATH_MAX) limitation.

Ref: curl#8361
Ref: curl#13512
Ref: https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats
Ref: https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation

Closes #xxxx
@nmoinvaz
Copy link
Contributor

@bagder is it possible for this to be merged for the next release? Thanks.

@bagder bagder removed the needs-info label Sep 15, 2024
@bagder
Copy link
Member

bagder commented Sep 15, 2024

@nmoinvaz this PR is done by @jay and he can/will merge this when he thinks it is fine.

@nmoinvaz
Copy link
Contributor

Ok I wasn't sure. I just wanted to make sure it wasn't abandoned because you told us on another PR that you closed it because we didn't push hard enough for it. Thanks!

@jay
Copy link
Member Author

jay commented Sep 16, 2024

This is held up by a CI failure in a Windows UWP job that I haven't had time to reproduce, apparently there is a missing GetFullPathNameW but according to the doc it exists in UWP apps

In file included from D:/a/curl/curl/bld/src/CMakeFiles/curl.dir/Unity/unity_0_c.c:139:
D:/a/curl/curl/lib/curl_multibyte.c: In function 'fix_excessive_path':
D:/a/curl/curl/lib/curl_multibyte.c:150:20: error: implicit declaration of function 'GetFullPathNameW'; did you mean 'GetLongPathNameW'? [-Wimplicit-function-declaration]
  150 |   needed = (size_t)GetFullPathNameW(in_w, 0, NULL, NULL);
      |                    ^~~~~~~~~~~~~~~~
      |                    GetLongPathNameW
D:/a/curl/curl/lib/curl_multibyte.c:150:20: error: nested extern declaration of 'GetFullPathNameW' [-Werror=nested-externs]
cc1.exe: all warnings being treated as errors
ninja: build stopped: subcommand failed.

The earliest this will be in a release is 2 months from now because it's not going in the patch release coming this Wednesday

@sergio-nsk
Copy link
Contributor

sergio-nsk commented Sep 16, 2024

  1. curl defines WIN32_LEAN_AND_MEAN. Thus, #include <fileapi.h> should be in setup-win32.h.
  2. If it does not help then Windows SDK should be upgraded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Windows Windows-specific
Development

Successfully merging this pull request may close these issues.

4 participants