[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:
co-authored by
OpenAI Codex
parent
877f6df889
commit
7173c64e2e
@@ -17,7 +17,7 @@ from vllm.utils.sparse_utils import (
|
||||
)
|
||||
|
||||
from ..image import convert_image_mode, normalize_image, open_image, rgba_to_rgb
|
||||
from .base import MediaIO, MediaWithBytes
|
||||
from .base import MediaDecodedBudget, MediaIO, MediaWithBytes
|
||||
|
||||
MAGIC_NUMPY_PREFIX = b"\x93NUMPY" # https://numpy.org/devdocs/reference/generated/numpy.lib.format.html#format-version-1-0
|
||||
|
||||
@@ -28,12 +28,19 @@ class ImageMediaIO(MediaIO[Image.Image]):
|
||||
error handling.
|
||||
"""
|
||||
|
||||
def __init__(self, image_mode: str | None = "RGB", **kwargs) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
image_mode: str | None = "RGB",
|
||||
*,
|
||||
decoded_budget: MediaDecodedBudget | None = None,
|
||||
**kwargs,
|
||||
) -> None:
|
||||
super().__init__()
|
||||
|
||||
# Target mode for loaded images; `None` keeps the original mode
|
||||
# (i.e. no conversion, alpha channel is preserved as-is).
|
||||
self.image_mode = image_mode
|
||||
self.decoded_budget = decoded_budget
|
||||
# `kwargs` contains custom arguments from
|
||||
# --media-io-kwargs for this modality, merged with
|
||||
# per-request runtime media_io_kwargs via merge_kwargs().
|
||||
@@ -87,6 +94,8 @@ class ImageMediaIO(MediaIO[Image.Image]):
|
||||
f"the maximum of {max_pixels} pixels. Set "
|
||||
f"VLLM_MAX_IMAGE_PIXELS to increase this limit."
|
||||
)
|
||||
if self.decoded_budget is not None:
|
||||
self.decoded_budget.charge(w * h * 4)
|
||||
image = normalize_image(image)
|
||||
image.load()
|
||||
converted = self._convert_image_mode(image)
|
||||
|
||||
Reference in New Issue
Block a user