pixelglow / ZipZap

zip file I/O library for iOS, macOS and tvOS
BSD 2-Clause "Simplified" License
1.22k stars 199 forks source link

Adress sanitycheck for aes encrypted zip #143

Open ghost opened 8 years ago

pixelglow commented 8 years ago

Thanks for your pull request. In general it looks good, but several minor issues to fix.

As a first pass, please rebase these to atomic commits. Each commit should be tightly focussed on one thing. For example:

Merge or drop typos and bad commits. Split up @18d7f9c into two commits. You can use a git rebase -i to do this and then git push --force to update this pull request.

Other general comments:

ghost commented 8 years ago

Hi thanks for your comments. I have just integrated those now.

Few comments on my side:

pixelglow commented 8 years ago

OK, a couple more minor edits and we should be done. Thanks for your work!

Please note that within the check of the local header (checkLocalHeader) I am now doing this check: _localFileHeader->compressionMethod != _centralFileHeader->compressionMethod instead of _localFileHeader->compressionMethod != self.compressionMethod.

That looks fine.

I believe i already asked but do you see a way to corrupt a local header by taking as ressource one of your encrypted AES file?

You can try corrupting a local header by open an NSData from the file, figuring what offset the zeroes have to be, writing some zeroes there and then open a ZZArchive with the data. If that's too finicky to work, I'm happy to accept the corrupted file in the test case.

ghost commented 8 years ago

I have integrated your last comments. I have managed also to corrupt the local header of your original small-test-encrypted-aes file by zeroing out some of the local header fields (versionNeededToExtract, generalPurposeBitFlag, compressionMethod, lastModFileName). This was feasible by identifying the local header signature in the file (504b 0304) and the offset for the next fields i wanted to zero out.

I hope this looks good to you now :-) - have a nice w.e!

pixelglow commented 8 years ago

I'm sorry for not getting back to you sooner -- had a busy month, both in life and work.

I really do appreciate the work you've put into this!

However, you'll need to be careful to respect the project style throughout. I see still quite a few bracket style exceptions. Please rebase to integrate any style fixes with the commits that originated them.

Also, where you've made certain methods part of the class extension, both the class extension methods and their implementation should be part of the same commit.

This is so that we can just inspect one commit and see everything that's needed to make it work there, rather than having to inspect multiple commits. Also helps git bisect and other automated debugging procedures.

Also, when I meant "corrupt the original test archive", I actually meant to do this in the test case e.g. in setUp and tearDown. This avoids having to include another zip file in the package, since we can copy the existing zip file and corrupt it for testing in setUp, then delete the copy in tearDown.