Hacker News new | past | comments | ask | show | jobs | submit login
Repairing Corrupted ZIP Files by Brute Force Scanning in C (zx2c4.com)
165 points by gnosis on May 22, 2011 | hide | past | favorite | 24 comments



+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.


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.


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.


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.


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


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


Just install the readbility firefox addon or go to: https://www.readability.com/read?url=http://blog.zx2c4.com/6...


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


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


Same with Firefox on XP. Even though the article is very interesting, trying to read the very thin font hurts my eyes and I had to stop reading.


Would you post a screenshot of the blunder, please?


http://i.imgur.com/wU8df.png

And here I was thinking it was just me...

EDIT: It's that 'LM Roman' font. Remove it and it will be fixed.


Hmmm so it doesn't render right on some browsers. Okay. I will fix this.

I really like Latin Modern/Computer Modern, just when it all goes to plan.

http://en.wikipedia.org/wiki/Computer_Modern


I've always found that font to be pretty terrible and makes Latex docs look less professional, but I guess if you are used to it from reading papers, it's the opposite.


Seems ok in IE though. The page looks like it's a latex export.


Actually, it's just a standard WordPress blog using the Latin Modern Roman typeface, which is based upon Computer Modern, the default in [La]TeX.

(I dig the TeX-lookalike WP theme, but it should really use other @font-face formats for compatibility, e.g., WOFF and EOT; that might make it look better in other browsers.)


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


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/


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.


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


Took about 35 minutes.


How is this different from what PKZIPFIX.EXE does?


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.


GUI plz




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: