Skip to content

Pkware encryption for Zip files didn't allow for multiple reads of an entry #197

Closed
@alexmgerasimov

Description

@alexmgerasimov

Hello!

I tried to use this library and faced some issues. Basically repeated reading of some zip archive entries leads to crashes. It seems that this is related to encrypted zips somehow. I'm using the following test code to reproduce the crashes:

	class Program
	{
		static void Main(string[] args)
		{
			try
			{
				using (var fileStream = File.Open(@"c:\Archive1.zip", FileMode.Open))
					UnpackMultipleTimes(fileStream, "12345678");
			}
			catch (Exception e)
			{				
			}
		}

		private static void UnpackMultipleTimes(Stream stream, string password)
		{
			using (var archive = ArchiveFactory.Open(stream, new ReaderOptions {Password = password}))
			{
				var entries = archive.Entries.Where(entry => !entry.IsDirectory);

				foreach (var entry in entries)
				{
					for (int i = 0; i < 100; i++)
					{
						using (var memoryStream = new MemoryStream())
						using (var entryStream = entry.OpenEntryStream())
						{
							entryStream.CopyTo(memoryStream);
						}
					}
				}
			}
		}
	}

Exception from Archive1.zip:

SharpCompress.Compressors.Deflate.ZlibException was unhandled
HResult=-2146233088
Message=Bad state (invalid block type)
Source=SharpCompress
StackTrace:
в SharpCompress.Compressors.Deflate.InflateManager.Inflate(FlushType flush)
в SharpCompress.Compressors.Deflate.ZlibBaseStream.Read(Byte[] buffer, Int32 offset, Int32 count)
в System.IO.Stream.InternalCopyTo(Stream destination, Int32 bufferSize)
в SevenZipTest.Program.UnpackMultipleTimes(Stream stream, String password)
в SevenZipTest.Program.Main(String[] args)
в System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
в System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
в Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
в System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
в System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
в System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
в System.Threading.ThreadHelper.ThreadStart()

I have several other archives with confidential data and can't share them. They produce exceptions with another messages. For example:

SharpCompress.Compressors.Deflate.ZlibException was unhandled
HResult=-2146233088
Message=Bad state (invalid literal/length code)
Source=SharpCompress
StackTrace:
в SharpCompress.Compressors.Deflate.InflateManager.Inflate(FlushType flush)
в SharpCompress.Compressors.Deflate.ZlibBaseStream.Read(Byte[] buffer, Int32 offset, Int32 count)
в System.IO.Stream.InternalCopyTo(Stream destination, Int32 bufferSize)
в SevenZipTest.Program.UnpackMultipleTimes(Stream stream, String password)
в SevenZipTest.Program.Main(String[] args)
в System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
в System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
в Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
в System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
в System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
в System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
в System.Threading.ThreadHelper.ThreadStart()

Can you fix this, please?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions