This project is read-only.

Unable to save .zip file from ASP.NET that includes password protected file

Apr 20, 2009 at 5:25 PM
Taking the DotNetZip - ASP.NET Example, simply add the line:
zip.Password = "password!";
right above the line:
zip.AddFileFromString("Readme.txt", "", ReadmeText); 

And receive the following error when it calls the Save method.

System.ArgumentOutOfRangeException was unhandled by user code
  Message="Specified argument was out of the range of valid values.\r\nParameter name: offset"
       at System.Web.HttpResponseStream.Write(Byte[] buffer, Int32 offset, Int32 count)
       at Ionic.Zip.CountingStream.Write(Byte[] buffer, Int32 offset, Int32 count)
       at Ionic.Zip.CountingStream.Write(Byte[] buffer, Int32 offset, Int32 count)
       at Ionic.Zip.ZipCipherStream.Write(Byte[] buffer, Int32 offset, Int32 count)
       at Ionic.Zlib.ZlibBaseStream.Write(Byte[] buffer, Int32 offset, Int32 length)
       at Ionic.Zlib.DeflateStream.Write(Byte[] buffer, Int32 offset, Int32 count)
       at Ionic.Zip.ZipEntry._WriteFileData(Stream s)
       at Ionic.Zip.ZipEntry._EmitOne(Stream outstream)
       at Ionic.Zip.ZipEntry.Write(Stream outstream)
       at Ionic.Zip.ZipFile.Save()
       at Ionic.Zip.ZipFile.Save(Stream outputStream)
       at ASP.default_aspx.btnGo_Click(Object sender, EventArgs e) in c:\Users\Chad\Documents\Visual Studio 2008\Projects\TestZipApp\WebApplication1\Default.aspx:line 139
       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

If I use different encryption from the default PkzipWeak (i.e. zip.Encryption = EncryptionAlgorithm.WinZipAes256;  ) then the file will download, but the encrypted files will not unzip - they are invalid.

Any idea on this?
Apr 22, 2009 at 4:01 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Apr 22, 2009 at 11:42 PM
Great, I'm glad it is a confrmed bug. Do you have any idea if this can be fixed in a near release? 
Apr 28, 2009 at 6:38 PM
Yes, it certainly can be fixed, but I don't have an estimate on when it might be fixed.
I'll look into it further, tonight, and I will then have a better idea.