peal.web.ingest.safe_extract

peal.web.ingest.safe_extract(zip_path, dest, max_files=20000, max_bytes=4294967296)[source]

Extract zip_path under dest after validating every member.

All members are checked before anything is written: absolute paths, .. components, symlinks, more than max_files files, a total uncompressed size above max_bytes and members with a suspicious compression ratio (BOMB_RATIO above BOMB_MIN_BYTES) are rejected.

Parameters:
  • zip_path (str) – Path of the uploaded zip archive.

  • dest (str) – Directory to extract into; created if missing.

  • max_files (int) – Maximum number of (non-directory) members.

  • max_bytes (int) – Maximum total uncompressed size in bytes.

Returns:

Number of files written.

Return type:

int

Raises:

IngestError – If the archive is not a zip file or any check fails.