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

FastZip.CreateZip crashes when used with certain buggy Directory enumeration on .NET 5 #676

Open
lscorcia opened this issue Oct 14, 2021 · 1 comment · May be fixed by #678
Open

FastZip.CreateZip crashes when used with certain buggy Directory enumeration on .NET 5 #676

lscorcia opened this issue Oct 14, 2021 · 1 comment · May be fixed by #678
Labels
enhancement Feature request or other improvements of existing functionality zip Related to ZIP file format

Comments

@lscorcia
Copy link

Not really a bug, more like a feature suggestion.

Steps to reproduce

  1. In .net 5, directory enumeration has bugs with WebDav (.Net Core Directory.GetFiles() operates webDav path dotnet/runtime#46723 (comment)), not fixed in .net 6 and with no other immediate official solution in sight;
  2. This causes crashes when calling FastZip.CreateZip as the GetDirectories/GetFiles return invalid data;
  3. A workaround is available - use something like this on the GetDirectories-returned data:
public static string[] FixupNet5Enumeration(string[] items)
{
    return items
        .Select(t => t.TrimEnd('\0'))
        .Where(t => {
            var itemName = Path.GetFileName(t);
            return itemName != "." && itemName != "..";
        })
        .ToArray();
}
  1. SharpZipLib nicely wraps the Directory.GetDirectories call into the FileSystemScanner class. However it is not possible to supply custom FileSystemScanners to FastZip.CreateZip. It would be helpful in this case as I could just copy that class and insert the required fixup calls. It would be necessary to create an interface around FileSystemScanner and to change to public the method

private void CreateZip(Stream outputStream, string sourceDirectory, bool recurse, FileSystemScanner scanner, bool leaveOpen)

What do you think?

Expected behavior

FastZip.CreateZip should offer an override to specify custom FileSystemScanners.

Actual behavior

FastZip.CreateZip throws exception as the paths returned by Directory.GetDirectories are not valid paths.

Version of SharpZipLib

1.3.3

Obtained from (only keep the relevant lines)

  • Package installed using NuGet
@piksel
Copy link
Member

piksel commented Oct 22, 2021

In general it seems like a good idea to make it possible to extend SharpZipLib as much as possible for the consumers own purposes, so making the FileSystemScanner customizable seems like a good idea.

The only concern I have is encouraging the use of FastZip in the first place. The reason for that, is that the decisions about what is acceptable behaviour is done inside the library, with no information of what the actual use case is. This doesn't apply as much to CreateZip as it does to extracting though...

@piksel piksel changed the title FastZip.CreateZip - how to deal with buggy Directory enumeration on .net 5 FastZip.CreateZip crashes when used with certain buggy Directory enumeration on .NET 5 Oct 22, 2021
@piksel piksel added enhancement Feature request or other improvements of existing functionality zip Related to ZIP file format labels Oct 22, 2021
@piksel piksel linked a pull request Oct 22, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request or other improvements of existing functionality zip Related to ZIP file format
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants