Malformed zip file should throw ZipException or BadReadException, not IOException

Jun 20, 2011 at 2:44 AM
Edited Jun 20, 2011 at 2:48 AM
I think that a malformed zip file should throw ZipException or BadReadException when calling ZipFile.Read().  The following code throws an IOException with the message "An attempt was made to move the file pointer before the beginning of the file."
Stack Trace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.SeekCore(Int64 offset, SeekOrigin origin)
at System.IO.FileStream.Seek(Int64 offset, SeekOrigin origin)
at Ionic.Zip.ZipFile.ReadIntoInstance(ZipFile zf)
at Ionic.Zip.ZipFile.Read(String fileName, TextWriter statusMessageWriter, Encoding encoding, EventHandler`1 readProgress)

string filePath = Path.GetTempFileName();
File.WriteAllText( filePath , "asdfasdf" );
string outputDirectory = Path.GetTempPath();
using ( ZipFile zipFile = ZipFile.Read( filePath ) )
     zipFile.ExtractAll( outputDirectory  );
Jun 22, 2011 at 2:57 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Jun 22, 2011 at 11:12 PM

I fixed this in changeset 79591.

This change will be in v1.9.1.6.  Due real soon now.

Jun 23, 2011 at 8:21 PM

Thanks for the quick turnaround on this, Cheeso!