Skip to main content

Provide secure unzip against zip bomb.

Project description


forthebadge made-with-python

PyPI Wheel Downloads version travis-ci codecov


Why are we doing this?

According to Cara Marie, an archive bomb a.k.a. A zip bomb is often employed to disable antivirus software, in order to create an opening for more traditional viruses. In addition, various kinds of pitfalls may occur during decompression.

PyCon Korea-Click Click Boom! Bombs Over Our Minds

Description for decompression pitfalls on zipfile doc

What is zip bomb?

It often appeared as a relatively small size zip file. And the unzipped file will be much larger than the zipped one. This would probably cause a problem when your disk volume or memory is relatively small than the unzipped one.

How do we defense zip bomb?

  • Defense Layer 1 - checks perform on the server side.
    1. Check if it's a nested zip file. (i.e.
    2. Check if the compression ratio (Uncompressed Content/Compressed Content)
       is greater than the threshold?
    3. Check if the file format is expected for context.
    4. Upload file size does not exceed the maximum limit.
  • Defense Layer 2 - limit the number of resources available to the process and its children.
    1. Check if CPU time is greater than the threshold.
    2. Check if the extracted part in memory is oversized. (memory usage)
  • Defense Layer 3 - filetype-specific mitigations.

    Filetype: Archives

    1. Restrict output file size and number of extracted files
       to ensure the total doesn't exceed the maximum limit.

How do we set thresholds?

Defense Layer 1:
  Uncompressed content size:  200 MB (vt)
  Compression ratio:

Defense Layer 2:
  CPU time:                   2 seconds(vt)
  Memoery oversized:

Defense Layer 3:
  Output file size:
  Number of extracted files:

Useful resources

Bomb Codes

Mitigation Summary

Defense layers


$ pip3 install sunzip
# for development use "development mode"
$ pip3 install -e <directory to project root>


# for command line usage see the help
$ sunzip-cli -h

You can find the arguments defined at the top of

import sunzip

f = sunzip.Sunzip("")

Customize your resource limit.

Maximum compression ratio threshold

f.threshold = 50

Maximum CPU time (second)

f.cpu = 1

Maximum memory usage (byte)

f.memory = 1024

Maximum file size (byte)

f.filesize = 1024

If there is no setting, the default value will be used.

extract() would perform a series of the above checks before decompression. If all pass, the zip file will be decompressed.

import sunzip

f = sunzip.Sunzip("")


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sunzip-0.0.5.tar.gz (5.9 kB view hashes)

Uploaded source

Built Distribution

sunzip-0.0.5-py3-none-any.whl (17.8 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page