VAITP Dataset

← Back to the dataset

CVE-2026-71870

Memory exhaustion via oversized /ToUnicode CMap parsing in pypdf before 6.15.0.

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

pypdf is a free and open-source pure-python PDF library. Prior to 6.15.0, a crafted PDF can cause large memory consumption when pypdf/_cmap.py function parse_bfrange parses unusually large source-code or destination-string tokens in a font /ToUnicode CMap during text extraction. This issue is fixed in 6.15.0.

CVSS base score
4.8
Published
2026-08-07
OWASP
A06 Vulnerable and Outdated Components
Orthogonal defect classification
Checking
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.15.0 or newer.

Vulnerable code sample

import re
from typing import List, Tuple

# Simplified mimic of pypdf._cmap.parse_bfrange
def parse_bfrange(token_stream: List[Tuple[str, str]]) -> List[Tuple[int, int, str]]:
    """
    Parses a list of (src, dst) token pairs from a CMap.
    Vulnerable: does not limit the size of the generated mapping,
    allowing crafted large ranges to consume excessive memory.
    """
    mapping: List[Tuple[int, int, str]] = []
    for src_token, dst_token in token_stream:
        # src_token and dst_token are hex strings like '<0001>' '<00FF>' or '<0020>'
        src = int(src_token.strip("<>"), 16)
        dst = int(dst_token.strip("<>"), 16)
        # VULNERABLE: directly creates a mapping entry for every code point in the range
        for cp in range(src, dst + 1):
            mapping.append((cp, cp, chr(cp)))
    return mapping

# Example token stream (the actual attack would use a huge range)
example_stream = [("<0000>", "<FFFF>")]
parse_bfrange(example_stream)

Patched code sample

import re
from typing import List, Tuple

MAX_RANGE_SIZE = 1000  # FIX: impose a reasonable upper bound on range size

def parse_bfrange(token_stream: List[Tuple[str, str]]) -> List[Tuple[int, int, str]]:
    """
    Parses a list of (src, dst) token pairs from a CMap.
    Fixed: validates the range size before expanding to prevent resource exhaustion.
    """
    mapping: List[Tuple[int, int, str]] = []
    for src_token, dst_token in token_stream:
        src = int(src_token.strip("<>"), 16)
        dst = int(dst_token.strip("<>"), 16)
        # FIX: reject or truncate excessively large ranges
        if dst - src + 1 > MAX_RANGE_SIZE:
            raise ValueError("CMap range too large")
        for cp in range(src, dst + 1):
            mapping.append((cp, cp, chr(cp)))
    return mapping

example_stream = [("<0000>", "<FFFF>")]
try:
    parse_bfrange(example_stream)
except ValueError:
    pass

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:cve202671870,
  title        = {{Memory exhaustion via oversized /ToUnicode CMap parsing in pypdf before 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-71870},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-71870/}}
}

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.