Skip to content

fix(vl): enforce default streaming byte cap on HTTP media downloads - #5249

Open
wsj040303 wants to merge 1 commit into
InternLM:mainfrom
wsj040303:wsj040303/fix-http-media-download-cap-5244
Open

wsj040303 wants to merge 1 commit into
InternLM:mainfrom
wsj040303:wsj040303/fix-http-media-download-cap-5244

Conversation

@wsj040303

Copy link
Copy Markdown

Motivation

Fixes #5244.

When load_from_url() / _load_http_url() is invoked without an explicit max_download_bytes argument—which includes OpenAI-compatible multimodal requests (MultimodalProcessor._parse_multimodal_item) and lmdeploy.vl.utils helpers—_load_http_url() fetches URLs without stream=True and buffers the entire response.content in memory before invoking media_io.load_bytes(). Even when URL scheme, _is_safe_url() global-IP validation, and allowed_media_domains checks pass, an HTTP endpoint serving a multi-gigabyte response causes unbounded memory growth and OOM termination.

Modification

  • Enforce a default streaming HTTP response-size cap in lmdeploy/vl/media/connection.py (DEFAULT_MEDIA_MAX_BYTES = 64 MiB, DEFAULT_VIDEO_MAX_BYTES = 256 MiB for VideoMediaIO), configurable by administrators via LMDEPLOY_MEDIA_MAX_BYTES, LMDEPLOY_IMAGE_MAX_BYTES, and LMDEPLOY_VIDEO_MAX_BYTES.
  • Allow media_io_kwargs (max_download_bytes) to tighten per-request budgets without exceeding the server-configured ceiling.
  • Always enable stream=True and _close_redirect_body in _load_http_url() so redirect responses, HTTP error responses, declared oversized Content-Length headers, and chunked/unknown-length streams abort before buffering unbounded payloads.
  • Keep compressed HTTP download support (gzip, x-gzip, deflate) on the default path via incremental zlib decompression bounded to the byte budget (preventing compressed payload amplification), while preserving strict Accept-Encoding: identity enforcement when callers pass an explicit max_download_bytes budget (such as DecisionImageIO).
  • Add unit, MultimodalProcessor, and local TCP HTTP server regression tests in tests/test_lmdeploy/test_vl/test_media_download.py.

BC-breaking (Optional)

Default HTTP(S) media downloads now reject payloads larger than 64 MiB (or 256 MiB for videos) unless raised via LMDEPLOY_MEDIA_MAX_BYTES, LMDEPLOY_IMAGE_MAX_BYTES, or LMDEPLOY_VIDEO_MAX_BYTES. Compressed (gzip/deflate) downloads within the budget and explicit max_download_bytes callers remain compatible.

Verification

Tested locally on Python 3.12 (CPU):

pytest tests/test_lmdeploy/test_vl/test_media_download.py \
  tests/test_lmdeploy/test_decision_images.py \
  tests/test_lmdeploy/test_content_merge.py -v
# 91 passed

ruff check lmdeploy/vl/media/connection.py tests/test_lmdeploy/test_vl/test_media_download.py
docformatter --check --wrap-descriptions 120 lmdeploy/vl/media/connection.py tests/test_lmdeploy/test_vl/test_media_download.py
double-quote-string-fixer lmdeploy/vl/media/connection.py tests/test_lmdeploy/test_vl/test_media_download.py
git diff --check

Checklist

  1. Pre-commit or other linting tools (ruff, docformatter, double-quote-string-fixer, LF line endings, git diff --check) are used to fix potential lint issues.
  2. The modification is covered by unit and streaming HTTP regression tests in tests/test_lmdeploy/test_vl/test_media_download.py.
  3. Existing DecisionImageIO, MultimodalProcessor, and safe-URL HTTP tests pass without regression.
  4. Updated load_from_url docstring to document the default HTTP byte budgets and environment variables.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] HTTP media loader buffers the full response without a size cap, causing OOM DoS

1 participant