SharpZipLib
SharpZipLib copied to clipboard
Zip file entries with backslashes does not get converted to slashes on nix platforms in FastZip.Extract
Steps to reproduce
- Create zip on Windows with backslash separators in paths
- Extract zip on Linux
new FastZip().ExtractZip(storageZipPath, storageBaseFolder)
Expected behavior
Backslashes should be changed to slashes on Linux
Actual behavior
Backslashes extracted as part of filename
Version of SharpZipLib
1.3.0, 1.3.1
Everything works fine in 1.2.0, maybe the bug relates to #54
Whoa, that sounds odd... How did you create that zip file? Zip files should never contain backslashes in the file names: https://p1k.se/appnote.md#s4.4.17.1
What is the output of unzip -Z -l YOUR_FILE.zip?
I use this command to compress files:
powershell Compress-Archive 'c:\my_folder\*' -DestinationPath my_backup.zip
The version of PowerShell is 5.1.18362.1474
Archive: test.zip
Zip file size: 42183935 bytes, number of entries: 431
-rw---- 2.0 fat 0 b- 0 stor 19-Jul-05 10:24 folder\sub\
-rw---- 2.0 fat 132135 b- 79653 defN 19-Jul-05 10:00 folder\sub\file.ext
...
Yep, confirmed. Powershell 5 creates zip-files with the wrong directory separator:
❯ unzip -Z -l test-ps5-wildcard.zip
Archive: test-wildcard.zip
Zip file size: 270 bytes, number of entries: 2
-rw---- 2.0 fat 0 b- 0 stor 21-May-25 14:42 TestFolder\TestFile1.txt
-rw---- 2.0 fat 0 b- 0 stor 21-May-25 14:42 TestFolder\TestFile2.txt
2 files, 0 bytes uncompressed, 0 bytes compressed: 0.0%
It works correctly in Powershell 7 though:
❯ unzip -Z -l test-ps7-wildcard.zip
Archive: test-ps7-wildcard.zip
Zip file size: 270 bytes, number of entries: 2
-rw---- 2.0 fat 0 b- 0 stor 21-May-25 14:42 TestFolder/TestFile1.txt
-rw---- 2.0 fat 0 b- 0 stor 21-May-25 14:42 TestFolder/TestFile2.txt
2 files, 0 bytes uncompressed, 0 bytes compressed: 0.0%
We could do the same thing as infozip does and replace them:
❯ unzip test-ps5-wildcard.zip
Archive: test-ps5-wildcard.zip
warning: test-ps5-wildcard.zip appears to use backslashes as path separators
extracting: TestFolder/TestFile1.txt
extracting: TestFolder/TestFile2.txt
Reference zip file with backslash (path\file):
UEsDBBQAAAAAAA14uVIAAAAAAAAAAAAAAAAJAAAAcGF0aFxmaWxlUEsBAhQAFAAAAAAADXi5UgAA
AAAAAAAAAAAAAAkAAAAAAAAAAAAAAAAAAAAAAHBhdGhcZmlsZVBLBQYAAAAAAQABADcAAAAnAAAA
AAA=
I've prepared a patch draft at https://github.com/Deplored/SharpZipLib/commit/f4f5641c7b99bf878a921a77984539867d01a323
这是来自QQ邮箱的假期自动回复邮件。 您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。