INNER CODE UNIT · Python
inspect_archive
KSwordDEV/KSword · GhidraRuntimePlugin/package.py:49
def inspect_archive(path: Path, profile: dict) -> dict:
if not path.is_file() or path.stat().st_size > profile['max_archive_bytes']:
raise ValueError('archive missing or exceeds pinned size bound')
digest = file_hash(path)
if digest != profile['sha256']:
raise ValueError('archive SHA256 differs from pinned upstream release')
files = {}
folded = set()
total = 0
with zipfile.ZipFile(path) as archive:
if len(archive.infolist()) > MAX_ENTRIES:
raise ValueError('too many ZIP entries')
for entry in archive.infolist():
relative = safe_member(entry.filename, profile['root_directory'])
mode = entry.external_attr >> 16
if stat.S_ISLNK(mode) or entry.flag_bits & 1:
raise ValueError('symlink or encrypted ZIP entry')
if entry.is_dir():