{"record":{"id":"6005ef35de565c72","repo":"iflytek/astron-agent","slug":"remote-resource-is-too-large","errorCode":null,"errorMessage":"Remote resource is too large","messagePattern":"Remote resource is too large","errorType":"exception","errorClass":"RemoteResourcePolicyError","httpStatus":null,"severity":"warning","filePath":"core/plugin/aitools/common/clients/safe_download.py","lineNumber":152,"sourceCode":"        connector=connector,\n        timeout=timeout,\n        trust_env=False,\n    ) as session:\n        async with session.get(url, allow_redirects=False) as response:\n            if not 200 <= response.status < 300:\n                raise RemoteResourcePolicyError(\n                    f\"Remote resource returned HTTP {response.status}\"\n                )\n            return await _read_bounded_response(response, max_bytes)\n\n\nasync def _read_bounded_response(\n    response: aiohttp.ClientResponse,\n    max_bytes: int,\n) -> bytes:\n    content_length = response.content_length\n    if content_length is not None and content_length > max_bytes:\n        raise RemoteResourcePolicyError(\"Remote resource is too large\")\n\n    content = bytearray()\n    async for chunk in response.content.iter_chunked(_DOWNLOAD_CHUNK_SIZE):\n        if len(content) + len(chunk) > max_bytes:\n            raise RemoteResourcePolicyError(\"Remote resource is too large\")\n        content.extend(chunk)\n    return bytes(content)\n\n\ndef _validate_resource_url(url: str) -> Tuple[SplitResult, bool]:\n    parsed = _parse_resource_url(url)\n    allow_private_storage = _is_configured_storage_url(parsed)\n    normalized_host = _normalize_hostname(parsed.hostname or \"\")\n    literal_address = _parse_ip(normalized_host)\n    if literal_address is not None:\n        _validate_destination_address(\n            literal_address,\n            allow_private_storage=allow_private_storage,","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/plugin/aitools/common/clients/safe_download.py#L134-L170","documentation":"_read_bounded_response first checks the response's Content-Length header; if it exceeds max_bytes (default 50MB, DEFAULT_MAX_DOWNLOAD_BYTES), the download is rejected before any body is read. This prevents memory exhaustion from oversized remote resources.","triggerScenarios":"The server declares a Content-Length larger than max_bytes for the requested resource; fetch_public_resource called with a reduced max_bytes against a large file.","commonSituations":"Downloading large videos/archives/datasets through an API that caps downloads at 50MB; caller lowered max_bytes to e.g. 1MB while the file is bigger; object URL points at a full archive rather than a thumbnail.","solutions":["If the payload is legitimately needed, pass a larger max_bytes to fetch_public_resource.","Serve/download a smaller artifact (compressed file, thumbnail, ranged/chunked retrieval) instead.","Verify you are not accidentally pointing at the wrong (larger) object URL."],"exampleFix":"// before\nawait fetch_public_resource(url)  # default 50 MB cap\n// after\nawait fetch_public_resource(url, max_bytes=200 * 1024 * 1024)  # allow 200 MB","handlingStrategy":"validation","validationCode":"# preflight with a HEAD request\nasync with aiohttp.ClientSession() as s:\n    async with s.head(url, allow_redirects=False) as r:\n        if int(r.headers.get(\"Content-Length\", 0)) > max_bytes:\n            raise ValueError(\"file too large\")","typeGuard":null,"tryCatchPattern":"try:\n    data = await fetch_public_resource(url, max_bytes=limit)\nexcept HTTPClientException as e:\n    if \"too large\" in str(e):\n        ...  # surface a 413-style error to the user","preventionTips":["Check Content-Length before downloading","Pick max_bytes deliberately per call site","Serve thumbnails/compressed variants for previews"],"tags":["http","payload-size","limit","python","download"],"backgroundTag":"payload-too-large","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}