Zipfile Extract -
with zipfile.ZipFile('untrusted.zip', 'r') as zip_ref: for member in zip_ref.namelist(): # Resolve the absolute path abspath = os.path.abspath(os.path.join('destination', member))
When extracting zip files, malicious archives can contain paths like ../../etc/passwd to write outside the destination folder.
Always use the with zipfile.ZipFile(...) syntax. This ensures the file handle is closed properly, even if an error occurs during extraction.
# Linux/macOS unzip your_file.zip -d destination_folder zipfile extract
zipfile — Work with ZIP archives — Python 3.14.4 documentation
A ZIP file is a common archive and compression standard that allows users to reduce the size of files for storage and improve transfer speeds over networks. By bundling multiple related files into a single, smaller package, ZIP files simplify data management and sharing. 1. Simple Extraction for Everyday Users
zipfile — Work with ZIP archives — Python 3.14.5rc1 documentation with zipfile
The zipfile module is a standard Python library used to read, write, and extract ZIP archives. Because it is built-in, you do not need to install anything extra.
Open the zipped folder and simply drag the desired file or folder to a new location on your desktop or another folder.
# Check if the file is inside the extract directory if not abs_path.startswith(os.path.abspath(extract_path)): raise Exception(f"Zip slip attempt blocked: member") # Linux/macOS unzip your_file
Extracts a specific member from the archive to the current or a specified directory. extractall()
extract()