libzip icon indicating copy to clipboard operation
libzip copied to clipboard

Zip a file with a path size superior to MAX_PATH

Open F4r3n opened this issue 3 years ago • 1 comments

Describe the Bug I can't zip a file with a path superior to the Windows path limit (260 characters).

Expected Behavior I should be able to zip the file

Observed Behavior zip_source_file returns NULL because it uses GetFileAttributesExW this function has a path size limit.

In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function (GetFileAttributesExW), and prepend "\?" to the path. For more information, see Naming a File.

libzip Version 1.8.2

Operating System Windows only

F4r3n avatar Jul 29 '22 09:07 F4r3n

We have no expertise on Windows. Do you have a patch suggestion?

0-wiz-0 avatar Jul 29 '22 09:07 0-wiz-0

The win32w backend already uses the recommended workaround (GetFileAttributesExW) so I suggest you use that - i.e. zip_source_win32w() or zip_source_win32w_create().

0-wiz-0 avatar Feb 03 '23 12:02 0-wiz-0

Here is some related code: https://github.com/dart-lang/sdk/blob/46bc947e75ca3ad2004e835e2b2698b61aab102f/runtime/bin/file_win.cc#L468-L469 https://github.com/openjdk/jdk/blob/e80b5ea448c715519d14e238321ceb5ec40b37f4/src/hotspot/os/windows/os_windows.cpp#L4440

I have never programmed for Windows though.

QrczakMK avatar Feb 03 '23 14:02 QrczakMK