The vulnerability, CVE-2026-102994, in pypdf concerns possible long runtimes and large memory usage when parsing indirect object headers that are not terminated by whitespace. This is a Denial of Service (DoS) vulnerability (CWE-400: Uncontrolled Resource Consumption, CWE-407: Inefficient Algorithmic Complexity).
The provided commit 82501d2993c6387833c4949d205caeb188f8bb9e and the associated pull request #4055 introduce length limits when reading parts of indirect objects.
Analysis of the patch reveals the following:
-
read_until_whitespace in pypdf/_utils.py: This is a core utility function used to read tokens from a stream until a whitespace character is encountered. The original implementation lacked any mechanism to limit the number of bytes read, making it susceptible to unbounded reading if a crafted input stream contained a very long sequence of non-whitespace characters. The patch adds max_bytes and strict parameters, enforcing a maximum length and raising LimitReachedError in strict mode.
-
IndirectObject.read_from_stream in pypdf/generic/_base.py: This static method is responsible for parsing indirect object references (object ID and generation number) directly from a PDF stream. The original code manually implemented a loop to read bytes until whitespace, without any length checks. This allowed an attacker to provide extremely long object IDs or generation numbers, leading to excessive memory allocation. The fix introduces _MAXIMUM_PART_LENGTH (set to 64 bytes) and a new read_part helper function that enforces this limit, raising PdfReadError if exceeded.
-
PdfReader.read_object_header in pypdf/_reader.py: This function is responsible for reading the header of an indirect object. It calls the read_until_whitespace utility function for both the object ID (idnum) and the generation number (generation). In the vulnerable version, these calls did not pass any max_bytes argument, meaning they relied on the unbounded behavior of read_until_whitespace. The patch modifies these calls to include max_bytes=IndirectObject._MAXIMUM_PART_LENGTH and strict=self.strict, thereby mitigating the vulnerability.
-
PdfReader._rebuild_xref_table in pypdf/_reader.py: This internal function processes object streams and also uses read_until_whitespace to parse inner_object_number and inner_offset. Similar to read_object_header, the original calls to read_until_whitespace in this function were unbounded. The patch updates these calls to include the max_bytes and strict arguments, preventing resource exhaustion during cross-reference table rebuilding.
When the vulnerability is exploited, a malicious PDF with oversized indirect object headers would be parsed. This would trigger the unbounded reading logic within read_until_whitespace (when called by read_object_header or _rebuild_xref_table) or the manual parsing loop in IndirectObject.read_from_stream, leading to excessive memory allocation and CPU usage, which would be visible in a runtime profiler for these specific functions.