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

Archives.ArchiveFactory.Open returns a ZipArchive but ZipArchive.IsZipFile is false #772

Open
njlr opened this issue Oct 4, 2023 · 3 comments

Comments

@njlr
Copy link

njlr commented Oct 4, 2023

#r "nuget: SharpCompress, 0.34.1"

open SharpCompress

let filePath = "./example.zip"

let isZipFile = Archives.Zip.ZipArchive.IsZipFile(filePath)

printfn $"isZipFile? %b{isZipFile}"

let archive = Archives.ArchiveFactory.Open(filePath)

printfn $"Archive type: %s{archive.GetType().FullName}"

printfn "Entries:"

for x in archive.Entries do
  printfn "%s" x.Key

Output:

isZipFile? false
Archive type: SharpCompress.Archives.Zip.ZipArchive
Entries:
Foo/
Foo/Bar.txt
System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at SharpCompress.Archives.Zip.ZipArchive.LoadEntries(IEnumerable`1 volumes)+MoveNext()
   at SharpCompress.LazyReadOnlyCollection`1.LazyLoader.MoveNext()
   at <StartupCode$FSI_0002>.$FSI_0002.main@() in /home/runner/Scratch.fsx:line 13
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
Stopped due to error

This suggests a bug in ArchiveFactory.Open to me - it shouldn't return a ZipArchive for a file where ZipArchive.IsZipFile is false.

I cannot share the zip file, unfortunately.

@btomblinson
Copy link
Contributor

@njlr do you have any way to share the .zip in question for reproducing this?

@DannyBoyk
Copy link
Contributor

The fact it can extract any entries at all implies it has at least some zip headers in it, even if IsZipFile returns false. This seems too specific to the zip file to be able to debug without it. I'm afraid you'll need to step through the headers in the file manually in something like HxD. The Wikipedia Zip file format article is a good reference. You need to try to figure out where things go off track.

@adamhathcock
Copy link
Owner

IsZipFile just checks if there is a valid header. This should probably change to use the magic bytes for the format. However, it can be a valid zip without the magic bytes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants