Files
VianoBugAnalysis/src/viano_bug_analysis/package/limits.py
T

23 lines
881 B
Python

from dataclasses import dataclass, fields
@dataclass(frozen=True)
class PackageLimits:
"""Configurable security policy, not restrictions of the v1 format."""
max_archive_bytes: int = 512 * 1024**2
max_total_bytes: int = 2 * 1024**3
max_file_bytes: int = 256 * 1024**2
max_manifest_bytes: int = 1024**2
max_entries: int = 10_000
max_compression_ratio: float = 200
def __post_init__(self) -> None:
import math
for item in fields(self):
value = getattr(self, item.name)
if isinstance(value, bool) or not isinstance(value, (int, float)) or not math.isfinite(value) or value <= 0:
raise ValueError(f"{item.name} must be positive and finite")
if item.name != "max_compression_ratio" and not isinstance(value, int):
raise ValueError(f"{item.name} must be an integer")