pyiron_base.utils.safetar.safe_extract

Contents

pyiron_base.utils.safetar.safe_extract#

pyiron_base.utils.safetar.safe_extract(tar: TarFile, path: str = '.', members: list = None, *, numeric_owner: bool = False) None[source]#

Safely extract the contents of a tar file.

This function checks if the extracted files are within the specified path to prevent path traversal attacks.

Parameters:
  • tar (tarfile.TarFile) – The tar file object.

  • path (str, optional) – The path to extract the files to. Defaults to “.”.

  • members (list, optional) – The members to extract. Defaults to None.

  • numeric_owner (bool, optional) – Whether to use numeric owner for extracted files. Defaults to False.

Raises:

Exception – If attempted path traversal is detected in the tar file.