icsharpcode / SharpZipLib

#ziplib is a Zip, GZip, Tar and BZip2 library written entirely in C# for the .NET platform.
http://icsharpcode.github.io/SharpZipLib/
MIT License
3.7k stars 976 forks source link

ZipOutputStream calls sync DeflaterOutputStream.Finish from async #801

Closed Christianschrodahl closed 1 year ago

Christianschrodahl commented 1 year ago

Steps to reproduce

  1. Create http get request.
  2. set AllowSynchronousIO to false
  3. Start zip json data and pdf docs
  4. Only use async methods to run the code.

Expected behavior

Return a zipped file

Actual behavior

You can se it crash on PutNextEntryAsync and/or finnishAsync. Looks like PutNextEntryAsync calls Finish() and not FinnishAsync()

Exception:

Exception has occurred: CLR/System.InvalidOperationException Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll: 'Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead.'

image

Version of SharpZipLib

1.4.1

Obtained from (only keep the relevant lines)

piksel commented 1 year ago

Yeah, this is caused by the following line: https://github.com/icsharpcode/SharpZipLib/blob/cdd0931e3c476faaf829963b2567619431c871bb/src/ICSharpCode.SharpZipLib/Zip/ZipOutputStream.cs#L608

It shouldn't be called inside WriteEntryFooter, but rather in the CloseEntry(Async) methods.