[Security] Bound decoded and downloaded media per request (#61226)

Signed-off-by: juanpas97 <juan.perezalgaba@gmail.com>
Signed-off-by: Juan Pérez de Algaba <jperezde@redhat.com>
Co-authored-by: OpenAI Codex <codex@openai.com>
This commit is contained in:
Juan Pérez de Algaba
2026-10-13 10:17:14 +00:00
committed by GitHub
co-authored by OpenAI Codex
parent 877f6df889
commit 7173c64e2e
16 changed files with 565 additions and 50 deletions
+10
View File
@@ -122,6 +122,16 @@ class VideoMediaIO(MediaIO[MediaWithBytes[tuple[DecodedFrames, dict[str, Any]]]]
video = self.video_loader.load_bytes(
data, num_frames=self.num_frames, **self.kwargs
)
frames = video[0] if isinstance(video, tuple) else video
budget = getattr(self.image_io, "decoded_budget", None)
shape = getattr(frames, "shape", None)
if budget is not None and shape is not None and len(shape) >= 3:
decoded_bytes = (
frames.numel() * frames.element_size()
if isinstance(frames, torch.Tensor)
else frames.nbytes
)
budget.charge(decoded_bytes)
return MediaWithBytes(video, data)
def load_base64(