Incorrect extraction of empty directory compressed with System.IO.Compression #90

Closed
opened 2026-01-29 22:06:25 +00:00 by claunia · 4 comments
Owner

Originally created by @zentron on GitHub (Mar 3, 2016).

When creating an zip file using the following standard powershell

Add-Type -Assembly System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::CreateFromDirectory($sourcedir, $zipfilename,  [System.IO.Compression.CompressionLevel]::Optimal, $false)

An empty folder has its file name encoded with a trailing \.
Although ZipFileEntry.cs correctly checks for trailing /, it doesn't consider this scenario.
Digging through the 7zip code, it seems they are also aware of this problem and have explicitly coded around it, noting in their comments that

.NET Framework 4.5 : System.IO.Compression::CreateFromDirectory() probably writes backslashes to headers? so we support that case

Originally created by @zentron on GitHub (Mar 3, 2016). When creating an zip file using the following standard powershell ``` Add-Type -Assembly System.IO.Compression.FileSystem [System.IO.Compression.ZipFile]::CreateFromDirectory($sourcedir, $zipfilename, [System.IO.Compression.CompressionLevel]::Optimal, $false) ``` An empty folder has its file name encoded with a trailing `\`. Although `ZipFileEntry.cs` [correctly checks](https://github.com/adamhathcock/sharpcompress/blob/681b28f6545ec745bcd42754f019a7cde23ca8a4/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs#L19) for trailing `/`, it doesn't consider this scenario. Digging through the 7zip code, it seems they are also aware of this problem and have explicitly coded around it, noting in their comments that > .NET Framework 4.5 : System.IO.Compression::CreateFromDirectory() probably writes backslashes to headers? so we support that case
Author
Owner

@zentron commented on GitHub (Mar 3, 2016):

Above PR supports these zip archives

@zentron commented on GitHub (Mar 3, 2016): Above PR supports these zip archives
Author
Owner

@adamhathcock commented on GitHub (Mar 3, 2016):

Any chance for a Pull request? Thanks!

@adamhathcock commented on GitHub (Mar 3, 2016): Any chance for a Pull request? Thanks!
Author
Owner

@zentron commented on GitHub (Mar 3, 2016):

sorry :) .. try check again.

@zentron commented on GitHub (Mar 3, 2016): sorry :) .. try check again.
Author
Owner

@adamhathcock commented on GitHub (Mar 3, 2016):

Thanks!

@adamhathcock commented on GitHub (Mar 3, 2016): Thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#90