### Development setup and verification commands Source: https://github.com/agent-scope-java/safeextract/blob/main/README.md Sets up a virtual environment, installs the package in editable mode with dev dependencies, runs the test suite, checks type correctness with mypy in strict mode, and executes the bomb demo script. ```sh python -m venv .venv && .venv/bin/pip install -e '.[dev]' .venv/bin/python -m pytest -q .venv/bin/python -m mypy src --strict python examples/bomb_demo.py ``` -------------------------------- ### Install safeextract with pip Source: https://github.com/agent-scope-java/safeextract/blob/main/README.md Install the safeextract package from PyPI. Requires Python 3.11 or newer; the package has zero runtime dependencies. ```sh pip install safeextract ``` -------------------------------- ### Bomb demo output: zipfile.extractall vs safeextract.extract Source: https://github.com/agent-scope-java/safeextract/blob/main/README.md Output of running `python examples/bomb_demo.py` on this machine, showing that `zipfile.extractall()` writes 200 MB with no ratio/size limit, while `safeextract.extract` refuses the entry because its compression ratio 100.3x exceeds the default `max_ratio` of 100.0. ```text one archive: 199 KB on disk, 200 MB in one entry (1028.2x) zipfile.extractall 57ms wrote 200 MB no ratio/size limit exists to refuse this safeextract.extract 8ms wrote 0 MB refused — entry 'data/payload.bin' compression ratio 100.3x exceeded max_ratio 100.0 (203842 stored bytes inflated to 20447232) ``` -------------------------------- ### Handle extraction errors with PathEscapeError and CompressionBombError Source: https://github.com/agent-scope-java/safeextract/blob/main/README.md Extract an archive while catching PathEscapeError and CompressionBombError. Quotas are enforced while each entry streams out of the decompressor, so a bomb stops as soon as it crosses a limit. Defaults are conservative; nothing is unbounded. ```python from safeextract import extract, CompressionBombError, PathEscapeError try: extract("plugin.tar.gz", dest) except PathEscapeError as exc: print(f"entry {exc.entry_name!r} tried to escape: {exc.reason}") except CompressionBombError as exc: print(f"{exc.compressed_bytes} bytes inflated to {exc.decompressed_bytes}") ``` -------------------------------- ### Extract archive with safeextract.extract and custom quotas Source: https://github.com/agent-scope-java/safeextract/blob/main/README.md Extract a ZIP archive with explicit quota and symlink policy. The format is detected from file contents, not the filename, so the same call works for .tar, .tar.gz, .tar.bz2, and .tar.xz archives. ```python from safeextract import extract extract("upload.zip", dest, max_entries=10_000, max_total_bytes=500 << 20, max_entry_bytes=100 << 20, max_ratio=100, symlinks="reject") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.