CVE-2026-119204
Excessive memory use in pypdf ≤6.21.3 via crafted page‑tree resource sharing.
- CVSS 7.1
- CWE-400
- Resource Management
- Remote
pypdf is a free and open-source pure-python PDF library. Prior to 6.21.4, pypdf can consume excessive memory while parsing a crafted PDF page tree containing many shared resources. Page-tree flattening copies page dictionary and inherited resource entries without a document-wide entry budget, allowing the crafted resource structure to cause disproportionate allocations. This issue is fixed in version 6.21.4.
- CWE
- CWE-400
- CVSS base score
- 7.1
- Published
- 2026-10-29
- OWASP
- A06 Vulnerable and Outdated Components
- Orthogonal defect classification
- Algorithm
- Code defect classification
- Incorrect Algorithm
- Category
- Resource Management
- Subcategory
- Resource Exhaustion
- Accessibility scope
- Remote
- Impact
- Denial of Service (DoS)
- Affected component
- pypdf
- Fixed by upgrading
- Yes
Solution
Upgrade pypdf to version 6.21.4 or later.
Vulnerable code sample
from pypdf import PdfReader, PdfWriter
def flatten_pages(src_path: str, dst_path: str):
"""
Reads a PDF, flattens the page tree by copying each page dictionary
and its inherited resources into a new PDF. No limit is imposed on
the number of pages/resources, which can lead to excessive memory use.
"""
reader = PdfReader(src_path)
writer = PdfWriter()
# VULNERABLE: unbounded copying of page resources may exhaust memory
for page in reader.pages:
# copy page dictionary and its resources verbatim
new_page = writer.add_page(page)
# inherit resources directly (pypdf does this internally)
# no budgeting or size check performed
with open(dst_path, "wb") as out_f:
writer.write(out_f)Patched code sample
from pypdf import PdfReader, PdfWriter
def flatten_pages(src_path: str, dst_path: str):
"""
Reads a PDF, flattens the page tree while enforcing a limit on the
number of pages processed to prevent memory exhaustion.
"""
reader = PdfReader(src_path)
writer = PdfWriter()
MAX_PAGES = 1000 # FIX: enforce a reasonable upper bound on processed pages
page_count = 0
for page in reader.pages:
if page_count >= MAX_PAGES:
break # stop processing to avoid excessive allocation
new_page = writer.add_page(page)
page_count += 1
with open(dst_path, "wb") as out_f:
writer.write(out_f)Published fix
Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.
- SEC: Limit the number of copied page attributes during flattening (#4290) (py-pdf/pypdf)
pypdf/_configuration.py,pypdf/_doc_common.py · PdfDocCommon.pages,pypdf/_doc_common.py · PdfDocCommon._flatten,pypdf/_doc_common.py · PdfDocCommon._flatten_leaf_page
Cite this entry
@misc{vaitp:cve2026119204,
title = {{Excessive memory use in pypdf ≤6.21.3 via crafted page‑tree resource sharing.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-119204},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-119204/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
