This project is read-only.

Receiving BadreadException

Dec 11, 2009 at 6:38 AM
Edited Dec 11, 2009 at 7:16 AM


We have been getting this exception suddenly today.

We have 2 applications where app1 (uses Vs2005) which is the admin app generates the zip files.

Then the app2 (uses Vs2008) which is the client app reads these files.

It was working fine till today morning and nothing has changed in the generation of zip file method but suddenly we have been getting this exception:

at Ionic.Zip.ZipEntry.ReadHeader(ZipEntry ze, Encoding defaultEncoding)
   at Ionic.Zip.ZipEntry.ReadEntry(ZipContainer zc, Boolean first)
   at Ionic.Zip.ZipFile.ReadIntoInstance_Orig(ZipFile zf)
   at Ionic.Zip.ZipFile.ReadIntoInstance(ZipFile zf)
   at Ionic.Zip.ZipFile.Read(String fileName, TextWriter statusMessageWriter, Encoding encoding, EventHandler`1 readProgress)
   at Ionic.Zip.ZipFile.Read(String fileName, TextWriter statusMessageWriter, Encoding encoding)
   at Ionic.Zip.ZipFile.Read(String fileName)



One other thing I have done is created a test console application using VS2005 and loaded the zip file successfully using:

ZipFile.Read method.

Please let us know if you have any suggestions



Dec 11, 2009 at 6:32 PM

I suspect something is wrong in the zip file. It has been corrupted, or it is not the same file you wrote. It's not the file you think it is.  

DotNetZip will not follow the code path in your message, unless the zip file is corrupted.

The clue is ReadIntoInstance_Orig().  It is a fallback approach. Normally DotNetZip scans to the end of a file, and works backward, looking for the central directory.  It goes back a maximum of 0x4000 bytes, (16384) which is more than enough for a normal zip file, and much more than enough for a zip file generated by DotNetZip itself.  Only if it fails to find the end of directory signature in the final 16384 bytes of the file, will DotNetZip resort to trying ReadIntoInstance_Orig . 

(The exception to this is if the input stream is non-seekable, because the normal approach requires seeking through the file.  But your filestream should be seekable) .

So... check your assumptions.  The file you're trying to read appears to NOT be a zip file.