VAITP Dataset

← Back to the dataset

CVE-2026-129227

Unbounded recursion in NLTK Tree.fromlist leads to RecursionError.

  • CVSS 5.3
  • CWE-674
  • Resource Management
  • Local

NLTK (Natural Language Toolkit) is a suite of open source Python modules, data sets, and tutorials supporting research and development in Natural Language Processing. Prior to 3.10.4, Tree.fromlist recursively converts nested Python list input into Tree objects without enforcing a maximum tree depth. An attacker-controlled list nested beyond the interpreter recursion limit can raise RecursionError and terminate the current parse operation or request worker. This issue is fixed in version 3.10.4.

CVSS base score
5.3
Published
2026-11-19
OWASP
A04 Insecure Design
Orthogonal defect classification
Checking
Code defect classification
Missing Check
Category
Resource Management
Subcategory
Resource Exhaustion
Accessibility scope
Local
Impact
Denial of Service (DoS)
Affected component
NLTK
Fixed by upgrading
Yes

Solution

Upgrade NLTK to version 3.10.4 or newer.

Vulnerable code sample

import sys
from nltk.tree import Tree

def build_tree(data):
    # VULNERABLE: unbounded recursion via Tree.fromlist
    return Tree.fromlist(data)

Patched code sample

import sys
from nltk.tree import Tree

def _safe_fromlist(lst, max_depth=1000, _cur=0):
    if _cur > max_depth:
        raise RecursionError("Maximum tree depth exceeded")
    if isinstance(lst, list):
        # first element is the node label, rest are children
        label = lst[0]
        children = [_safe_fromlist(item, max_depth, _cur + 1) for item in lst[1:]]
        return Tree(label, children)
    return lst

def build_tree(data):
    # FIX: enforce a maximum tree depth
    return _safe_fromlist(data)

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.

  • Fix tree.py (nltk/nltk)
    nltk/tree/tree.py, nltk/tree/tree.py · Tree.fromlist

Cite this entry

@misc{vaitp:cve2026129227,
  title        = {{Unbounded recursion in NLTK Tree.fromlist leads to RecursionError.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-129227},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-129227/}}
}

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.