{"record":{"id":"b92aafc1f73fb831","repo":"sgl-project/sglang","slug":"remote-media-exceeds-the-max-bytes-byte-download","errorCode":null,"errorMessage":"Remote media exceeds the {max_bytes} byte download limit","messagePattern":"Remote media exceeds the (.+?) byte download limit","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/utils/common.py","lineNumber":1644,"sourceCode":"            location = response.headers.get(\"Location\")\n            if response.status_code in _MEDIA_URL_REDIRECT_STATUS_CODES and location:\n                if redirect_count == _MAX_MEDIA_URL_REDIRECTS:\n                    raise requests.exceptions.TooManyRedirects(\n                        f\"Media URL exceeded {_MAX_MEDIA_URL_REDIRECTS} redirects: {url}\"\n                    )\n                current_url = urljoin(response.url, location)\n                continue\n\n            response.raise_for_status()\n            max_bytes = _media_url_max_file_size_bytes\n            content_length = response.headers.get(\"Content-Length\")\n            if max_bytes and content_length is not None:\n                try:\n                    declared_size = int(content_length)\n                except ValueError:\n                    declared_size = None\n                if declared_size is not None and declared_size > max_bytes:\n                    raise ValueError(\n                        f\"Remote media exceeds the {max_bytes} byte download limit\"\n                    )\n\n            content = bytearray()\n            for chunk in response.iter_content(chunk_size=64 * 1024):\n                if not chunk:\n                    continue\n                if time.monotonic() > deadline:\n                    raise requests.exceptions.Timeout(\n                        f\"Timed out while downloading media URL: {url}\"\n                    )\n                if max_bytes and len(content) + len(chunk) > max_bytes:\n                    raise ValueError(\n                        f\"Remote media exceeds the {max_bytes} byte download limit\"\n                    )\n                content.extend(chunk)\n            return bytes(content)\n","sourceCodeStart":1626,"sourceCodeEnd":1662,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/utils/common.py#L1626-L1662","documentation":"During download, the server's Content-Length header declares a size larger than the configured max_bytes limit, so download_remote_media aborts before reading the body. This is the first line of the byte-limit enforcement, protecting worker memory from oversized media.","triggerScenarios":"Fetching a video/image whose Content-Length exceeds the max-file-size policy (default _DEFAULT_MEDIA_URL_MAX_FILE_SIZE_MB); a server liesing with a huge Content-Length also triggers it.","commonSituations":"Large video files exceeding the default media size cap; client uploads referencing multi-GB files; hostile servers trying to exhaust memory.","solutions":["Raise --media-url-max-file-size-mb (or configure_media_url_security(max_file_size_mb=...)) to fit the real asset size","Compress/downsample the media before hosting it","Reject oversized requests client-side with a clear message"],"exampleFix":"# before\npython -m sglang.launch_server  # default cap, 2GB video fails\n# after\npython -m sglang.launch_server --media-url-max-file-size-mb 8192","handlingStrategy":"validation","validationCode":"# client-side: HEAD the asset and compare against the configured cap\nimport requests\nsize = int(requests.head(url, timeout=10).headers.get('Content-Length', 0))\nif size > MAX_BYTES: raise ClientError('media too large; compress or raise the cap')","typeGuard":null,"tryCatchPattern":"try:\n    data = download_remote_media(url, timeout=30)\nexcept ValueError as e:\n    if 'download limit' in str(e):\n        return HTTPException(413, 'remote media exceeds configured size limit')\n    raise","preventionTips":["Size the cap to your largest expected video asset","Pre-check Content-Length client-side to fail fast"],"tags":["media","size-limit","download","security"],"backgroundTag":"download-size-limit-exceeded","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}