{"record":{"id":"3ce49bd599460f17","repo":"docling-project/docling","slug":"downloaded-data-exceeds-size-limit","errorCode":null,"errorMessage":"Downloaded data exceeds size limit","messagePattern":"Downloaded data exceeds size limit","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"docling/backend/utils/image_resource_loader.py","lineNumber":244,"sourceCode":"\n            session.hooks[\"response\"].append(_check_redirect_safety)\n\n            response = session.get(\n                src_loc, stream=True, headers=headers, timeout=(5, 30)\n            )\n            response.raise_for_status()\n\n            content_length = response.headers.get(\"content-length\")\n            if content_length and int(content_length) > max_size:\n                raise ValueError(f\"Resource size exceeds limit: {content_length} bytes\")\n\n            chunks = []\n            total_size = 0\n            for chunk in response.iter_content(chunk_size=8192):\n                if chunk:\n                    total_size += len(chunk)\n                    if total_size > max_size:\n                        raise ValueError(\"Downloaded data exceeds size limit\")\n                    chunks.append(chunk)\n\n            return b\"\".join(chunks)\n        elif src_loc.startswith(\"data:\"):\n            encoded_data = re.sub(r\"^data:image/.+;base64,\", \"\", src_loc)\n            decoded_data = base64.b64decode(encoded_data)\n\n            if len(decoded_data) > self.max_image_data_base64_bytes:\n                raise ValueError(\n                    f\"Decoded image exceeds size limit of {self.max_image_data_base64_bytes} bytes.\"\n                )\n\n            return decoded_data\n\n        if not self.enable_local_fetch:\n            raise OperationNotAllowed(\n                \"Fetching local resources is only allowed when set explicitly. \"\n                \"Set options.enable_local_fetch=True.\"","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/docling-project/docling/blob/61d76f1ff3f8428065465889f7b4577da7df704c/docling/backend/utils/image_resource_loader.py#L226-L262","documentation":"While streaming a remote image, the total bytes received crossed max_remote_image_bytes (default 20 MiB). This triggers when the content-length header was absent or understated (chunked responses) so the pre-flight check [80] could not catch it. The download is aborted mid-stream to bound memory usage.","triggerScenarios":"Remote image fetched with enable_remote_fetch=True where the server omits or lies about content-length (chunked transfer encoding), and the accumulated 8192-byte chunks exceed max_remote_image_bytes.","commonSituations":"CDNs using chunked encoding; servers that ignore the Range request header; dynamically generated images with unknown size; malicious servers deliberately hiding size.","solutions":["Raise options max_remote_image_bytes to cover the real image sizes you expect.","Point the document at a hosted, correctly-sized variant of the image.","If the remote resource is untrusted, keep the limit and accept that the image is skipped (create_image_ref warns and returns None).","Host the asset locally and use enable_local_fetch with base_path instead of remote fetching."],"exampleFix":"# before\nconv_opts = PipelineOptions()  # default 20 MiB remote image cap\n\n# after\nfrom docling.datamodel.pipeline_options import HtmlPipelineOptions\nhtml_opts = HtmlPipelineOptions()\nhtml_opts.max_remote_image_bytes = 200 * 1024 * 1024","handlingStrategy":"try-catch","validationCode":"import urllib.request\n\ndef remote_image_within_limit_streamed(url: str, max_bytes: int) -> bool:\n    # no reliable pre-check when content-length is absent; HEAD first, else expect abort\n    req = urllib.request.Request(url, method=\"HEAD\")\n    with urllib.request.urlopen(req, timeout=10) as resp:\n        cl = resp.headers.get(\"content-length\")\n        return cl is None or int(cl) <= max_bytes","typeGuard":null,"tryCatchPattern":"try:\n    data = loader.load_image_data(src, base_path)\nexcept ValueError as e:\n    logger.warning(\"image %s exceeded streamed size limit: %s\", src, e)\n    data = None","preventionTips":["Size-limit remote fetches at the HTTP layer too (proxy/max body size) for untrusted inputs.","Keep enable_remote_fetch=False unless remote images are required; local/served variants avoid the issue.","Treat missing content-length as potentially-oversized when auditing inputs."],"tags":["network","images","size-limit","streaming"],"backgroundTag":null,"analyzedSha":"61d76f1ff3f8428065465889f7b4577da7df704c","analyzedAt":"2026-08-14T23:53:18.727Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}