4
Vote

BadReadException on byte[1179648]

description

http://stackoverflow.com/questions/15337186/dotnetzip-badreadexception-on-extract
public class Program
{
    public static void Main(string[] args)
    {
        var source = new FileInfo("foo.txt");
        using (var writer = source.CreateText())
            writer.Write(new string('a', 1179648));

        var target = new FileInfo(Path.ChangeExtension(source.FullName, "zip"));
        var folder = new DirectoryInfo(Path.ChangeExtension(source.FullName, null));

        if (target.Exists)
            target.Delete();

        if (folder.Exists)
            folder.Delete(true);

        using (var zip = new ZipFile(target.FullName))
        {
            zip.AddFile(source.FullName, string.Empty);
            zip.Save();
        }

        using (var zip = new ZipFile(target.FullName))
            zip.ExtractAll(folder.FullName);
    }
}
Unhandled Exception: Ionic.Zip.BadReadException: bad read of entry foo.txt from compressed archive.
   at Ionic.Zip.ZipEntry._CheckRead(Int32 nbytes)
   at Ionic.Zip.ZipEntry.ExtractOne(Stream output)
   at Ionic.Zip.ZipEntry.InternalExtract(String baseDir, Stream outstream, String password)
   at Ionic.Zip.ZipFile._InternalExtractAll(String path, Boolean overrideExtractExistingProperty)
   at Ionic.Zip.ZipFile.ExtractAll(String path)
   at ConsoleApplication1.Program.Main(String[] args) in C:\ZipDemo\ConsoleApplication1\ConsoleApplication1\Program.cs:line 32

file attachments

comments

Steam wrote Mar 11, 2013 at 12:59 PM

Was able to replicate this issue. Code works well with v1.9. Attached sample code with working version (using v1.9 of DotNetZip)

VS2012 used for testing.

wrote Apr 2, 2013 at 9:33 PM

wrote May 23, 2013 at 6:47 AM

wrote Aug 20, 2013 at 3:05 PM

ichris wrote Aug 20, 2013 at 3:06 PM

This is probably a duplicate of https://dotnetzip.codeplex.com/workitem/14087