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 1: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.

ichris wrote Aug 20, 2013 at 4:06 PM

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