CVE-2026-71852
DoS via crafted PDF causing high CPU/memory in pypdf <6.15.0
- CVSS 4.8
- CWE-834
- Resource Management
- Remote
pypdf is a free and open-source pure-python PDF library. Prior to 6.15.0, a crafted PDF can cause long runtimes and large memory consumption when pypdf/_font.py function Font._collect_cid_character_widths expands unusually large CID font /W width ranges or excessive width entries during text extraction. This issue is fixed in 6.15.0.
- CWE
- CWE-834
- CVSS base score
- 4.8
- Published
- 2026-08-07
- OWASP
- A04 Insecure Design
- 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.15.0 or later.
Vulnerable code sample
import typing
from pypdf._font import Font
class MyFont(Font):
def _collect_cid_character_widths(self, font_dict: dict) -> typing.Dict[int, int]:
"""Collect CID character widths from the /W entry."""
# VULNERABLE: unbounded expansion of CID width ranges can exhaust resources
widths = {}
for cid_range in font_dict.get("/W", []):
if isinstance(cid_range, list):
start = cid_range[0]
if len(cid_range) == 3:
# single width entry: [start, end, width]
for cid in range(start, cid_range[1] + 1):
widths[cid] = cid_range[2]
else:
# list of widths: [start, width1, width2, ...]
for offset, w in enumerate(cid_range[1:]):
widths[start + offset] = w
return widthsPatched code sample
import typing
from pypdf._font import Font
class MyFont(Font):
def _collect_cid_character_widths(self, font_dict: dict) -> typing.Dict[int, int]:
"""Collect CID character widths from the /W entry."""
# FIX: limit expansion to prevent resource exhaustion
MAX_ENTRIES = 10000
widths = {}
entry_count = 0
for cid_range in font_dict.get("/W", []):
if isinstance(cid_range, list):
start = cid_range[0]
if len(cid_range) == 3:
end = cid_range[1]
width = cid_range[2]
range_len = end - start + 1
if entry_count + range_len > MAX_ENTRIES:
break
for cid in range(start, end + 1):
widths[cid] = width
entry_count += range_len
else:
for offset, w in enumerate(cid_range[1:]):
if entry_count >= MAX_ENTRIES:
break
widths[start + offset] = w
entry_count += 1
return widthsPublished 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 CID width range and width count when loading fonts (#3946) (py-pdf/pypdf)
pypdf/_font.py,pypdf/_font.py · Font.from_font_resource,pypdf/_font.py · Font._collect_cid_character_widths
Cite this entry
@misc{vaitp:cve202671852,
title = {{DoS via crafted PDF causing high CPU/memory in pypdf <6.15.0}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-71852},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-71852/}}
}
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 ::
