Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Fixes #5244.
When
load_from_url()/_load_http_url()is invoked without an explicitmax_download_bytesargument—which includes OpenAI-compatible multimodal requests (MultimodalProcessor._parse_multimodal_item) andlmdeploy.vl.utilshelpers—_load_http_url()fetches URLs withoutstream=Trueand buffers the entireresponse.contentin memory before invokingmedia_io.load_bytes(). Even when URL scheme,_is_safe_url()global-IP validation, andallowed_media_domainschecks pass, an HTTP endpoint serving a multi-gigabyte response causes unbounded memory growth and OOM termination.Modification
lmdeploy/vl/media/connection.py(DEFAULT_MEDIA_MAX_BYTES = 64 MiB,DEFAULT_VIDEO_MAX_BYTES = 256 MiBforVideoMediaIO), configurable by administrators viaLMDEPLOY_MEDIA_MAX_BYTES,LMDEPLOY_IMAGE_MAX_BYTES, andLMDEPLOY_VIDEO_MAX_BYTES.media_io_kwargs(max_download_bytes) to tighten per-request budgets without exceeding the server-configured ceiling.stream=Trueand_close_redirect_bodyin_load_http_url()so redirect responses, HTTP error responses, declared oversizedContent-Lengthheaders, and chunked/unknown-length streams abort before buffering unbounded payloads.gzip,x-gzip,deflate) on the default path via incrementalzlibdecompression bounded to the byte budget (preventing compressed payload amplification), while preserving strictAccept-Encoding: identityenforcement when callers pass an explicitmax_download_bytesbudget (such asDecisionImageIO).MultimodalProcessor, and local TCP HTTP server regression tests intests/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, orLMDEPLOY_VIDEO_MAX_BYTES. Compressed (gzip/deflate) downloads within the budget and explicitmax_download_bytescallers 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 --checkChecklist
ruff,docformatter,double-quote-string-fixer, LF line endings,git diff --check) are used to fix potential lint issues.tests/test_lmdeploy/test_vl/test_media_download.py.DecisionImageIO,MultimodalProcessor, and safe-URL HTTP tests pass without regression.load_from_urldocstring to document the default HTTP byte budgets and environment variables.