Skip to content

symfonic.kernel.contracts.archive_limits

archive_limits

Private, dependency-free inspection of zip container declarations.

ArchiveLimitExceeded

Bases: ValueError

A zip is malformed or one of its declared resource bounds is exceeded.

inspect_zip_limits

inspect_zip_limits(payload: bytes, *, max_uncompressed_bytes: int, max_expansion_ratio: float, max_members: int, max_nesting_depth: int) -> None

Reject a zip whose central-directory declarations exceed a ceiling.

Source code in src/symfonic/kernel/contracts/archive_limits.py
def inspect_zip_limits(
    payload: bytes,
    *,
    max_uncompressed_bytes: int,
    max_expansion_ratio: float,
    max_members: int,
    max_nesting_depth: int,
) -> None:
    """Reject a zip whose central-directory declarations exceed a ceiling."""
    _inspect_zip(
        payload,
        max_uncompressed_bytes=max_uncompressed_bytes,
        max_expansion_ratio=max_expansion_ratio,
        max_members=max_members,
        max_nesting_depth=max_nesting_depth,
        nesting_depth=1,
    )

is_zip_container

is_zip_container(media_type: str, payload: bytes) -> bool

Return whether bytes should be treated as a zip-backed container.

Source code in src/symfonic/kernel/contracts/archive_limits.py
def is_zip_container(media_type: str, payload: bytes) -> bool:
    """Return whether bytes should be treated as a zip-backed container."""
    return payload.startswith(b"PK") or media_type in _ZIP_MEDIA_TYPES