Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
alexmgerasimov opened this issue Nov 18, 2016 · 5 comments
Labels

Comments

@alexmgerasimov
Copy link

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?

@adamhathcock
Copy link
Owner

I reproduced this.

This is specific to PKWare encryption as the encryptor is stateful and reused on multiple runs. I'll fix that.

I'm still getting an error. Probably something else is stateful and needs to be reset.

@alexmgerasimov
Copy link
Author

alexmgerasimov commented Nov 21, 2016

Thank you for the quick response!
Is there any chance you can fix this issues in the near future?

@adamhathcock
Copy link
Owner

I'm doing this in my free time as I take breaks from work. Not sure when I'll fix it. This one I haven't figured out yet.

@alexmgerasimov
Copy link
Author

Thank you for merging our pull request to the master!
Can you please advise when the new version of the Nuget package will be released?

@adamhathcock
Copy link
Owner

I will try to do a release Monday.

@adamhathcock adamhathcock changed the title Multiple crashes on repeated zip archives reading Pkware encryption for Zip files didn't allow for multiple reads of an entry Nov 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants