

Repairing Corrupted ZIP Files by Brute Force Scanning in C - gnosis
http://blog.zx2c4.com/605

======
eps
+1 for questioning or ignoring commonly accepted assumptions.

Such as that compressed archives are hard if possible at all to repair. Or,
say, that the optimal encoding is a very hard problem... something that David
Huffman simply didn't know when he came up with his coding algorithm.

------
daeken
Very cool article. If you are going to have a bunch of packed structs, though,
it's often easier to wrap all the structs in #pragma pack(0)/pack() rather
than putting the attribute on each member. This is an MSism, but it works in
gcc.

~~~
zx2c4
Thanks a lot for this tip! Saves a lot of writing. I knew there had to be a
better way...

Ideally, I guess I wouldn't read directly into a struct, though, and instead
use the right functions from endian.h to make the code portable, but ah! such
is life when you're scrambling to save a zip and the post-graduation nostalgia
is high and the post-coffee-crash caffeination is low.

------
VMG
When I use my hacking skills for something like this, I sometimes fear that I
am wasting time and a normal person would have solved this problem faster and
easier because he isn't focused on programming all the time.

Nice to see that the fun way is the right way in this case.

------
Garbage
That's a real hacker's work! :)

Though I recommend to read the nice post, here is the direct link to the code:
<http://git.zx2c4.com/BruteZip/tree/read.c>

------
ZoFreX
I'mn afraid your blog post is almost completely unreadable in Chrome and Opera
on Windows 7.

~~~
dmn001
Just install the readbility firefox addon or go to:
[https://www.readability.com/read?url=http://blog.zx2c4.com/6...](https://www.readability.com/read?url=http://blog.zx2c4.com/605)

~~~
RyanKearney
He said Chrome, so a Firefox addon won't do him much good.

~~~
dmn001
It looks bad on Firefox too. I also gave a link which works on any browser,
and that includes Chrome.

------
zdw
It would be a great service to a whole lot of people for this method to be
integrated into commonly used zip utilities.

------
sehugg
I'm surprised that zip -FF wouldn't work. Sounds like it needs your patch,
although it looks from the InfoZip source that the fix functionality is spread
throughout the zip parsing code rather than isolated into a small routine like
this one.

What would be interesting is a utility that could fix archives uploaded via
FTP with ASCII mode accidentally turned on. This page claims to have a method:
<http://bukys.com/services/recovery/examples/>

~~~
nitrogen
This must be a problem that a lot of hackers have solved, as I've written
about how to solve that same problem in my (unpublished) idea archive.

------
bshep
Just out of curiosity, how long did it take to process the huge zip file?

~~~
zx2c4
Took about 35 minutes.

------
kragen
How is this different from what PKZIPFIX.EXE does?

~~~
kragen
The original author responded to my comment above with the link
<http://blog.zx2c4.com/605#comment-5889>, which is to a comment that claims
that PKZIPFIX does the same thing. Unfortunately it's been [dead]ed.

------
jewpiterjones
GUI plz

