{"record":{"id":"623efa940f97076f","repo":"docling-project/docling","slug":"xml-file-member-name-exceeds-size-limit-of-self","errorCode":null,"errorMessage":"XML file {member.name} exceeds size limit of {self.options.max_file_bytes} bytes","messagePattern":"XML file (.+?) exceeds size limit of (.+?) bytes","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"docling/backend/mets_gbs_backend.py","lineNumber":271,"sourceCode":"        )\n        self.root_mets: etree._Element | None = None\n        self.page_map: dict[int, _PageFiles] = {}\n        self._total_bytes_extracted = 0\n        member_count = 0\n\n        for member in self._tar.getmembers():\n            member_count += 1\n            if member_count > self.options.max_member_count:\n                raise ValueError(\n                    f\"Archive exceeds maximum member count limit of {self.options.max_member_count}\"\n                )\n\n            if member.name.endswith(\".xml\"):\n                file = self._tar.extractfile(member)\n                if file is not None:\n                    content = file.read(self.options.max_file_bytes + 1)\n                    if len(content) > self.options.max_file_bytes:\n                        raise ValueError(\n                            f\"XML file {member.name} exceeds size limit of {self.options.max_file_bytes} bytes\"\n                        )\n\n                    self._total_bytes_extracted += len(content)\n                    if self._total_bytes_extracted > self.options.max_total_bytes:\n                        raise ValueError(\n                            f\"Archive exceeds maximum total extraction size of {self.options.max_total_bytes} bytes\"\n                        )\n\n                    self.root_mets = self._validate_mets_xml(content)\n                    if self.root_mets is not None:\n                        break\n\n        if self.root_mets is None:\n            raise DocumentLoadError(\n                f\"METS GBS backend could not load document {self.document_hash}.\"\n            )\n","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/docling-project/docling/blob/61d76f1ff3f8428065465889f7b4577da7df704c/docling/backend/mets_gbs_backend.py#L253-L289","documentation":"ValueError raised while scanning XML members of a METS/GBS tar archive during init: a member ending in .xml is read with a cap of max_file_bytes+1 bytes, and if more than max_file_bytes bytes come back the member is rejected. This is an individual-file decompression-bomb guard.","triggerScenarios":"Converting a METS GBS archive containing an .xml member whose uncompressed size exceeds options.max_file_bytes (e.g. a multi-hundred-MB METS or OCR XML). The read(max_file_bytes+1) trick detects the overflow with a single bounded read.","commonSituations":"Books with extremely detailed OCR/ALTO XML, concatenated multi-volume METS files, hostile archives with a gzipped XML bomb, or a user-configured max_file_bytes that is too small for legitimately large metadata.","solutions":["Increase the per-file cap: MetsGbsBackendOptions(max_file_bytes=...) sized to your largest legitimate XML member.","Check the member with `tar -tvzf file.tar.gz | sort -k3 -n` to see which XML is oversized and whether it is legitimate.","Strip or split unneeded giant XML sidecars from the archive before conversion.","Leave the guard on for untrusted archives — it prevents memory blowups from XML decompression bombs."],"exampleFix":"# before\nresult = converter.convert(mets_path)  # ValueError: XML exceeds size limit\n\n# after\nopts = MetsGbsBackendOptions(max_file_bytes=512 * 1024 * 1024)\n# wire opts into the converter's format options, then:\nresult = converter.convert(mets_path)","handlingStrategy":"validation","validationCode":"import tarfile\n\ndef largest_xml_within(tar_path: str, cap: int) -> bool:\n    with tarfile.open(tar_path) as t:\n        return all(m.size <= cap for m in t.getmembers() if m.name.endswith('.xml'))","typeGuard":null,"tryCatchPattern":"try:\n    result = converter.convert(mets_path)\nexcept ValueError as e:\n    if 'exceeds size limit' in str(e) and '.xml' in str(e):\n        log.error('oversized XML member in %s: %s', mets_path, e)\n        raise  # decide: raise the cap or reject the archive","preventionTips":["Set max_file_bytes above the largest XML member measured via tar -tvzf.","Keep oversized ALTO/OCR sidecars out of packages you ship to docling.","Retain the limit for untrusted archives to block XML bombs."],"tags":["mets","archive","security","limits","xml"],"backgroundTag":null,"analyzedSha":"61d76f1ff3f8428065465889f7b4577da7df704c","analyzedAt":"2026-08-14T23:53:18.727Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}