How to protect myself from a gzip or bzip2 bomb?

前端 未结 5 1240
眼角桃花
眼角桃花 2020-12-15 06:53

This is related to the question about zip bombs, but having gzip or bzip2 compression in mind, e.g. a web service accepting .tar.gz files.

Python provid

5条回答
  •  失恋的感觉
    2020-12-15 07:31

    If you develop for linux, you can run decompression in separate process and use ulimit to limit the memory usage.

    import subprocess
    subprocess.Popen("ulimit -v %d; ./decompression_script.py %s" % (LIMIT, FILE))
    

    Keep in mind that decompression_script.py should decompress the whole file in memory, before writing to disk.

提交回复
热议问题