3 ms·
Is there a way to check for decompression bombs? I'd like my software to be able to unzip zip files safely.
by andrewstuart 11y ago
Is there a way to check for decompression bombs? I'd like my software to be able to unzip zip files safely.
- ZenoArrow 11y agoMonitor zip files as they decompress. Halt decompression process if the size ratio between zip file and decompressed file exceeds a fixed ratio (for example, if ratio between the file sizes is something like 10:1).
- Ambroos 11y agoIf you do that, pick something a little more extreme. When using BEM, for example, your CSS becomes pretty repetitive and you easily get better than 10:1 ratio with GZIP, for example.
- wglb 11y agoYes. A method whose only purpose is to answer the question 'is this file larger than <parameter>'. If it is don't go further.
- wiredfool 11y agoYou can do it in zlib -- there's one call that effectively does the whole thing, and one that fills a buffer. You can check to see how much input has been consumed, if there's more, then you know you're getting large. It's up to the friendly programmer to decide when large is too large.
- MatthewWilkes 11y agoA python example: def decompress(data, maxsize=262144): dec = zlib.decompressobj() data = dec.decompress(data, maxsize) if dec.unconsumed_tail: raise ValueError("Possible zip Bomb") del dec return data
- bluedino 11y agoSandbox them. We once created a 1024MB, 6GB disk single-core VM and built a tiny API around image decompression and scaling. Never had any issues with it, but it was a simple way of preventing things from filling up the regular web servers.