The vulnerability, CVE-2026-48155, allows an attacker to cause a denial-of-service by crafting a PDF that consumes a large amount of memory during text extraction in layout mode. The root cause lies in the processing of text positioning operators within the PDF content. The pypdf library's layout mode text extraction feature calculates the amount of whitespace (spaces and newlines) to generate based on coordinate values in the PDF. The vulnerability is that there were no limits on these calculated values.
Analysis of the patch in PR #3790 reveals two key functions where the vulnerability is present and was subsequently fixed:
-
recurse_to_target_op (renamed from recurs_to_target_op): This function processes text drawing commands. It was vulnerable because the calculation for the number of spaces (spaces) between text fragments could be manipulated to be a very large number, leading to the allocation of a huge string.
-
fixed_width_page: This function builds the final text page layout. It was vulnerable in two ways: first, by calculating the number of blank_lines between text based on vertical positioning, and second, by calculating needed_spaces for horizontal alignment. Both calculations could result in extremely large numbers when processing a malicious PDF.
The patch addresses these issues by introducing WHITESPACE_LIMIT and NEWLINE_LIMIT to cap the number of spaces and newlines that can be generated, thus preventing uncontrolled memory allocation.