docstr: Fix for CVE-2007-4559
  Desc:
      Directory traversal vulnerability in the (1) extract and (2) extractall functions in the tarfile
      module in Python allows user-assisted remote attackers to overwrite arbitrary files via a .. (dot dot)
      sequence in filenames in a TAR archive, a related issue to CVE-2001-1267.
  See: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-4559
  From: https://stackoverflow.com/a/10077309
docstr_tok: ["Fix","for","CVE-2007-4559","Desc",":","Directory","traversal","vulnerability","in","the","(","1",")","extract","and","(","2",")","extractall","functions","in","the","tarfile","module","in","Python","allows","user-assisted","remote","attackers","to","overwrite","arbitrary","files","via","a","..","(","dot","dot",")","sequence","in","filenames","in","a","TAR","archive",",","a","related","issue","to","CVE-2001-1267",".","See",":","https",":","\/\/cve.mitre.org\/cgi-bin\/cvename.cgi","?","name=CVE-2007-4559","From",":","https",":","\/\/stackoverflow.com\/a\/10077309"]
code: def safemembers(members, output_path):
      """
      Fix for CVE-2007-4559
      Desc:
          Directory traversal vulnerability in the (1) extract and (2) extractall functions in the tarfile
          module in Python allows user-assisted remote attackers to overwrite arbitrary files via a .. (dot dot)
          sequence in filenames in a TAR archive, a related issue to CVE-2001-1267.
      See: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-4559
      From: https://stackoverflow.com/a/10077309
      """
  
      def resolved(path: str) -> str:
          return os.path.realpath(os.path.abspath(path))
  
      def badpath(path: str, base: str) -> bool:
          # joinpath will ignore base if path is absolute
          return not resolved(os.path.join(base, path)).startswith(base)
  
      def badlink(info, base: str) -> bool:
          # Links are interpreted relative to the directory containing the link
          tip = resolved(os.path.join(base, os.path.dirname(info.name)))
          return badpath(info.linkname, base=tip)
  
      base = resolved(output_path)
  
      for finfo in members:
          if badpath(finfo.name, base):
              logger.error(
                  f"Extraction of {finfo.name} is blocked (illegal path)"
              )
          elif finfo.issym() and badlink(finfo, base):
              logger.error(
                  f"Extraction of {finfo.name} is blocked: Symlink to {finfo.linkname}"
              )
          elif finfo.islnk() and badlink(finfo, base):
              logger.error(
                  f"Extraction of {finfo.name} is blocked: Hard link to {finfo.linkname}"
              )
          else:
              yield finfo
  
imports: import bz2
  import gzip
  import lzma
  import os
  import shutil
  import struct
  import tarfile
  import warnings
  import zipfile
  from abc import ABC, abstractmethod
  from pathlib import Path
  from typing import Dict, List, Optional, Type, Union
  from ..None import config
  from ._filelock import FileLock
  from .logging import get_logger
label_desc: Use image node_id 2 for calling the TarExtractor obj's underlying member method code with example usage: obj.safemembers(members, output_path) and returns: os, unknown, badpath