(archive: tarfile.TarFile, layer_info: Dict)
Extracts File objects to be scanned for given layer.
Extracts File objects to be scanned for given layer.
Extracts File objects to be scanned for given layer .
def _get_layer_files(archive: tarfile.TarFile, layer_info: Dict) -> Iterable[File]:
    """
    Extracts File objects to be scanned for given layer.
    """
    layer_filename = layer_info["filename"]
    layer_archive = tarfile.TarFile(
        name=os.path.join(archive.name, layer_filename),  # type: ignore
        fileobj=archive.extractfile(layer_filename),
    )

    for file_info in layer_archive:
        if not file_info.isfile():
            continue

        if file_info.size > MAX_FILE_SIZE * 0.95:
            continue

        if any(dir in "/" + file_info.path for dir in DEFAULT_FS_BANLIST):
            continue

        if any(file_info.path.endswith(ext) for ext in DEFAULT_EXTENSION_BANLIST):
            continue

        file = layer_archive.extractfile(file_info)
        if file is None:
            continue

        file_content_raw = file.read()
        if len(file_content_raw) > MAX_FILE_SIZE * 0.95:
            continue

        file_content = (
            file_content_raw.decode(errors="replace")
            .replace("\0", " ")  # null character, not replaced by replace
            .replace("\uFFFD", " ")  # replacement character
        )
        yield File(
            document=file_content,
            filename=os.path.join(archive.name, layer_filename, file_info.name),  # type: ignore # noqa
            filesize=file_info.size,
        )
def _get_layer_files ( archive : tarfile . TarFile , layer_info : Dict ) -> Iterable [ File ] : layer_filename = layer_info [ "filename" ] layer_archive = tarfile . TarFile ( name = os . path . join ( archive . name , layer_filename ) , # type: ignore fileobj = archive . extractfile ( layer_filename ) , ) for file_info in layer_archive : if not file_info . isfile ( ) : continue if file_info . size > MAX_FILE_SIZE * 0.95 : continue if any ( dir in "/" + file_info . path for dir in DEFAULT_FS_BANLIST ) : continue if any ( file_info . path . endswith ( ext ) for ext in DEFAULT_EXTENSION_BANLIST ) : continue file = layer_archive . extractfile ( file_info ) if file is None : continue file_content_raw = file . read ( ) if len ( file_content_raw ) > MAX_FILE_SIZE * 0.95 : continue file_content = ( file_content_raw . decode ( errors = "replace" ) . replace ( "\0" , " " ) # null character, not replaced by replace . replace ( "\uFFFD" , " " ) # replacement character ) yield File ( document = file_content , filename = os . path . join ( archive . name , layer_filename , file_info . name ) , # type: ignore # noqa filesize = file_info . size , )