VAITP Dataset

← Back to the dataset

CVE-2026-102995

Memory‑exhaustion via oversized /ToUnicode tokens in pypdf < 6.18.1.

  • CVSS 8.7
  • CWE-400
  • Resource Management
  • Remote

pypdf is a free and open-source pure-python PDF library. Prior to 6.18.1, a crafted PDF can place unusually large source-code or destination-string tokens in a font /ToUnicode mapping, causing pypdf/_cmap.py parse_bfchar to decode and retain oversized values during operations such as text extraction and consume excessive memory. This is a second follow-up to earlier /ToUnicode resource-consumption fixes and is limited to the remaining token-length path. This issue is fixed in version 6.18.1.

CVSS base score
8.7
Published
2026-09-30
OWASP
A05 Security Misconfiguration
Orthogonal defect classification
Timing/Serialization
Code defect classification
Missing Check
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.18.1 or later.

Vulnerable code sample

import io
from pypdf._cmap import parse_bfchar

def extract_text(pdf_bytes: bytes) -> str:
    """
    Extracts text from a PDF by parsing its /ToUnicode CMap.
    This version does not limit token size and can be abused
    by a crafted PDF containing an oversized token.
    """
    stream = io.BytesIO(pdf_bytes)
    # VULNERABLE: parses bfchar entries without size check, leading to memory exhaustion
    bfchar_map = parse_bfchar(stream)
    text = "".join(bfchar_map.get(b, "?") for b in bfchar_map)
    return text

Patched code sample

import io
from pypdf._cmap import parse_bfchar

MAX_TOKEN_LEN = 1024  # FIX: impose reasonable limit on token length

def extract_text(pdf_bytes: bytes) -> str:
    """
    Extracts text from a PDF by parsing its /ToUnicode CMap.
    This version limits token size to prevent resource exhaustion.
    """
    stream = io.BytesIO(pdf_bytes)
    # FIX: filter out entries whose source or destination token exceeds the limit
    raw_map = parse_bfchar(stream)
    bfchar_map = {
        src: dst for src, dst in raw_map.items()
        if len(src) <= MAX_TOKEN_LEN and len(dst) <= MAX_TOKEN_LEN
    }
    text = "".join(bfchar_map.get(b, "?") for b in bfchar_map)
    return text

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.

Cite this entry

@misc{vaitp:cve2026102995,
  title        = {{Memory‑exhaustion via oversized /ToUnicode tokens in pypdf < 6.18.1.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-102995},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-102995/}}
}

Download this entry as JSON Download the whole dataset

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 ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.