haf / DotNetZip.Semverd

Please use System.IO.Compression! A fork of the DotNetZip project without signing with a solution that compiles cleanly. This project aims to follow semver to avoid versioning conflicts. DotNetZip is a FAST, FREE class library and toolset for manipulating zip files. Use VB, C# or any .NET language to easily create, extract, or update zip files.
Other
546 stars 218 forks source link

Zip Archive corruption when modifying an AES Encrypted archive #153

Open Numpsy opened 5 years ago

Numpsy commented 5 years ago

Hi,

I've been attempting to track down an old issue whereby modifying the comment field on an AES encrypted zip that was created with WinZip/7-Zip results in the file being labelled as corrupted (the same issue as described under the 'Trivial code to modify and save a zip corrupts AES encrypted content' topic in the issues page @ https://archive.codeplex.com/?p=dotnetzip).

My knowledge of how the AES stuff works is rather basic, but trying to debug the tests, what seems to be happening is that:

Changing the write @ https://github.com/haf/DotNetZip.Semverd/blob/master/src/Zip.Shared/ZipEntry.Write.cs#L394 to check for the existing value of 'this._WinZipAesMethod' and retaining the value of '2' if already set seems to fix this case, but i'm not sure if that';s right in the general case (perhaps it should only by 2 in the case where the file hasn't been modified, or iff the CRC is 0?). Anyone have any ideas?

There is an example of a unit test that fails with the current code @ https://github.com/Numpsy/DotNetZip.Semverd/commit/950ffb31a862dac8177e1991b7d3cb07e05fc193

Thanks.

haf commented 4 years ago

Thanks for reporting this bug/problem, and sorry about the delay in getting back to you. This is a self-service repository, where I merge PRs and where the merging of PRs causes nugets to be pushed automatically (if you bump the version number in your PR). I'll leave this issue open until someone (or yourself) fixes it.