[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
+44 -16
View File
@@ -23,7 +23,7 @@ from vllm.utils.sparse_utils import (
safe_to_dense,
)
from .base import MediaIO
from .base import MediaDecodedBudget, MediaIO
logger = init_logger(__name__)
@@ -527,8 +527,11 @@ class AudioMediaIO(MediaIO[tuple[npt.NDArray, float]]):
error handling.
"""
def __init__(self, **kwargs) -> None:
def __init__(
self, *, decoded_budget: MediaDecodedBudget | None = None, **kwargs
) -> None:
super().__init__()
self.decoded_budget = decoded_budget
# Allow per-server override of the audio decoding backend, e.g.:
# --media-io-kwargs '{"audio": {"audio_backend": "torchcodec"}}'
@@ -564,13 +567,44 @@ class AudioMediaIO(MediaIO[tuple[npt.NDArray, float]]):
def load_bytes(self, data: bytes) -> tuple[npt.NDArray, float]:
self._validate_encoded_size(len(data))
return load_audio(
BytesIO(data),
sr=None,
max_duration_s=envs.VLLM_MAX_AUDIO_DECODE_DURATION_S,
max_decode_bytes=envs.VLLM_MAX_AUDIO_DECODE_BYTES,
backend=self.audio_backend,
)
return self._load_with_budget(BytesIO(data))
def _load_with_budget(self, source: BytesIO | Path) -> tuple[npt.NDArray, float]:
budget = self.decoded_budget
if budget is None:
return load_audio(
source,
sr=None,
max_duration_s=envs.VLLM_MAX_AUDIO_DECODE_DURATION_S,
max_decode_bytes=envs.VLLM_MAX_AUDIO_DECODE_BYTES,
backend=self.audio_backend,
)
max_decode_bytes = envs.VLLM_MAX_AUDIO_DECODE_BYTES
reserved = budget.reserve(max_decode_bytes)
decoded_bytes = 0
try:
try:
audio = load_audio(
source,
sr=None,
max_duration_s=envs.VLLM_MAX_AUDIO_DECODE_DURATION_S,
max_decode_bytes=reserved,
backend=self.audio_backend,
)
except ValueError as exc:
if reserved < max_decode_bytes and "VLLM_MAX_AUDIO_DECODE_BYTES" in str(
exc
):
raise ValueError(
"Request decoded media exceeds "
"VLLM_MAX_MEDIA_REQUEST_DECODE_BYTES."
) from exc
raise
decoded_bytes = audio[0].nbytes
return audio
finally:
budget.settle(reserved, decoded_bytes)
def load_base64(
self,
@@ -588,13 +622,7 @@ class AudioMediaIO(MediaIO[tuple[npt.NDArray, float]]):
def load_file(self, filepath: Path) -> tuple[npt.NDArray, float]:
self._validate_encoded_size(filepath.stat().st_size)
return load_audio(
filepath,
sr=None,
max_duration_s=envs.VLLM_MAX_AUDIO_DECODE_DURATION_S,
max_decode_bytes=envs.VLLM_MAX_AUDIO_DECODE_BYTES,
backend=self.audio_backend,
)
return self._load_with_budget(filepath)
def encode_base64(
self,