{"record":{"id":"f0855a94497f1787","repo":"sgl-project/sglang","slug":"media-url-max-file-size-mb-must-be-non-negative","errorCode":null,"errorMessage":"media_url_max_file_size_mb must be non-negative","messagePattern":"media_url_max_file_size_mb must be non-negative","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/utils/common.py","lineNumber":1564,"sourceCode":"        raise ValueError(f\"Invalid allowed media domain {domain!r}\") from e\n    if not normalized:\n        raise ValueError(\"allowed media domains cannot be empty\")\n    return normalized\n\n\ndef configure_media_url_security(\n    allowed_media_domains: Optional[Sequence[str]] = None,\n    max_file_size_mb: int = _DEFAULT_MEDIA_URL_MAX_FILE_SIZE_MB,\n) -> list[str]:\n    \"\"\"Configure process-wide safeguards for client-supplied media URLs.\n\n    A serving worker hosts one engine configuration, while media loading fans\n    out to worker threads. Keeping the immutable policy here makes the same\n    checks apply to image, video, audio, cache, and model-specific loaders.\n    \"\"\"\n\n    if max_file_size_mb < 0:\n        raise ValueError(\"media_url_max_file_size_mb must be non-negative\")\n\n    normalized_domains = sorted(\n        {_normalize_media_domain(domain) for domain in allowed_media_domains or []}\n    )\n    global _allowed_media_domains, _media_url_max_file_size_bytes\n    _allowed_media_domains = frozenset(normalized_domains)\n    _media_url_max_file_size_bytes = max_file_size_mb * 1024 * 1024\n    return normalized_domains\n\n\ndef _assert_media_url_allowed(url: str) -> None:\n    parsed = urlparse(url)\n    if parsed.scheme not in {\"http\", \"https\"} or parsed.hostname is None:\n        raise ValueError(f\"Invalid media URL: {url!r}\")\n\n    hostname = _normalize_media_domain(parsed.hostname)\n    if _allowed_media_domains and hostname not in _allowed_media_domains:\n        raise ValueError(","sourceCodeStart":1546,"sourceCodeEnd":1582,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/utils/common.py#L1546-L1582","documentation":"configure_media_url_security validates that media_url_max_file_size_mb is >= 0 and rejects negative values. The limit (converted to bytes for the global policy) protects serving workers from unbounded media downloads; a negative limit is meaningless and usually a config arithmetic mistake.","triggerScenarios":"Passing max_file_size_mb=-1 (or a negative computed value, e.g. derived from a CLI flag) to configure_media_url_security; hit at scheduler/worker startup via __init__ or _handle_media_url_security, or in tests setUp.","commonSituations":"CLI parsing that accepts negatives, config files with a typo'd negative number, code that computes 'unlimited = -1' semantics that this API does not support (use 0 to disable).","solutions":["Use 0 to disable the size limit instead of a negative value","Clamp at config parse time: max(0, int(value))","Fix the typo'd number in the config file"],"exampleFix":"# before\nconfigure_media_url_security(max_file_size_mb=-1)\n# after\nconfigure_media_url_security(max_file_size_mb=0)  # 0 = no limit","handlingStrategy":"validation","validationCode":"max_file_size_mb = max(0, int(raw_value))  # 0 disables the limit\nconfigure_media_url_security(max_file_size_mb=max_file_size_mb)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp numeric config at parse time","Use 0 (not -1) to mean unlimited"],"tags":["validation","media","security","config"],"backgroundTag":"config-validation-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}