{"record":{"id":"c4b102df51183251","repo":"docling-project/docling","slug":"resource-size-exceeds-limit-content-length-byte","errorCode":null,"errorMessage":"Resource size exceeds limit: {content_length} bytes","messagePattern":"Resource size exceeds limit: (.+?) bytes","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"docling/backend/utils/image_resource_loader.py","lineNumber":236,"sourceCode":"                    redirect_url = response.headers.get(\"location\")\n                    if redirect_url:\n                        # Handle relative redirects\n                        if not redirect_url.startswith((\"http://\", \"https://\")):\n                            redirect_url = urljoin(response.url, redirect_url)\n\n                        # Validate the redirect target\n                        validate_url_safety(redirect_url)\n\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.\"","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/docling-project/docling/blob/61d76f1ff3f8428065465889f7b4577da7df704c/docling/backend/utils/image_resource_loader.py#L218-L254","documentation":"The HTML/Markdown backend's ImageResourceLoader refuses to download a remote image because the HTTP response declares a content-length larger than max_remote_image_bytes (default 20 MiB, wired from pipeline options). It is a defense against decompression/quota attacks from untrusted documents. The check happens before any body is streamed, so no bytes are downloaded.","triggerScenarios":"Converting an HTML or Markdown document whose <img src>/![]() points at an http(s) URL whose server returns a content-length header greater than options.max_remote_image_bytes; only fires when enable_remote_fetch=True already allowed the request.","commonSituations":"Documents embedding very large photographs or print-resolution scans (common in report-heavy HTML exports); a low custom max_remote_image_bytes set by a security team; servers reporting total file size even when a Range header was sent.","solutions":["Raise the limit: set max_remote_image_bytes (e.g. 50*1024*1024) in your pipeline options if the images are legitimately large.","If the image is genuinely needed smaller, pre-process the source document to reference resized images.","If the URL is wrong or points at an unintended huge asset, fix or remove the src in the input document.","Accept the degraded conversion: create_image_ref already warns and skips oversized images, so verify whether the missing image actually matters for your output."],"exampleFix":"# before\npipeline_options = HtmlPipelineOptions()\npipeline_options.do_images_enhance = True\n\n# after\npipeline_options = HtmlPipelineOptions()\npipeline_options.max_remote_image_bytes = 100 * 1024 * 1024","handlingStrategy":"try-catch","validationCode":"import urllib.request\n\ndef remote_image_within_limit(url: str, max_bytes: int) -> bool:\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    img_ref = loader.load_image_ref(src, base_path)\nexcept ValueError as e:  # covers both size-limit ValueErrors\n    logger.warning(\"skipping oversized image %s: %s\", src, e)\n    img_ref = None","preventionTips":["Set max_remote_image_bytes to the largest legitimate image in your corpus before converting.","Audit documents for huge remote assets during ingestion and downscale or reject them early.","Remember create_image_ref already downgrades this to a warning; only direct load_image_data calls raise."],"tags":["network","images","size-limit","html","markdown"],"backgroundTag":null,"analyzedSha":"61d76f1ff3f8428065465889f7b4577da7df704c","analyzedAt":"2026-08-14T23:53:18.727Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}