Impersonation problem when using 7z encryption

Aug 21, 2011 at 3:58 PM

This is a complex bug which required a lot of testing from me.

My application is a windows service that runs as the system account. This means that it by default does not have network access. I use "standard" calls to impersonation methods to get network access. This code I have been using is working on all operating system and I have been using it for years.

My problem, is, whenever I try to compress files located on a network drive, is that sevenzipsharp creates an archive (on my local drive) and first, successfully, adds the first file of about 10 files. Then, on the following files it adds zero byte files.

I am using other compression formats from your library without any problems. This happens only when using the 7z method.

When looking at the facts, that I first have network access on first file but not on second my experience tell me that you are doing some special threading when calling 7z methods. Someway, this new threading causes the impersonation on my thread to fail.

I can reproduce this problem every time. It has nothing to do with the size of the file. For example - I am able to compress a 400 mB file but it fails at the second file which could be 1kB. I use the exact same code for normal zip files (just changing the archive format) - but when using zip it adds all files properly.

As this is important for me to work I am willing to test a lot with your help. Thank you.