Zip Bomb

A zip bomb is a small compressed file that expands to an enormous size when it is extracted, filling up the disk or memory of whatever tries to open it.

Compression algorithms work by replacing repeated data with short references to it, so a file full of zeros compresses fantastically well. The best-known zip bomb, 42.zip, is 42 kilobytes. It contains layers of nested archives which, fully unpacked, come to about 4.5 petabytes. (Nobody has checked by hand.)

Zip bombs are a form of denial-of-service attack. If your application accepts file uploads and then decompresses them, scans them for viruses or generates previews, a single upload can exhaust the server's disk space or memory. To protect yourself, set limits on the total uncompressed size, the number of files and the depth of nesting before you extract an archive, and stop extracting as soon as any limit is reached.

Further Reading

Learn it hands-on

File uploads are an easy way for an attacker to inject malicious code into your application.