CVE-2026-129222
Unbounded recursion in NLTK DependencyGraph can cause RecursionError.
- CVSS 7.5
- 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, DependencyGraph.tree and DependencyGraph.triples walk parsed dependency edges through unbounded Python recursion and do not use a working cycle or depth guard. A crafted CoNLL or Malt-TAB dependency file containing a sufficiently long chain can raise RecursionError when the documented traversal APIs are called, aborting the current worker. This issue is fixed in version 3.10.4.
- CWE
- CWE-674
- CVSS base score
- 7.5
- 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 3.10.4
- Fixed by upgrading
- Yes
Solution
Upgrade NLTK to version 3.10.4 or newer.
Vulnerable code sample
from nltk.parse import DependencyGraph
def extract_tree(conll_str: str):
"""
Parse a CoNLL formatted dependency string and return its tree representation.
This uses DependencyGraph.tree which recurses without a depth guard.
"""
dg = DependencyGraph(conll_str)
# VULNERABLE: unbounded recursion in DependencyGraph.tree
return dg.tree()Patched code sample
from nltk.parse import DependencyGraph
def extract_tree(conll_str: str):
"""
Parse a CoNLL formatted dependency string and return its tree representation.
This version adds a simple depth guard to prevent unbounded recursion.
"""
dg = DependencyGraph(conll_str)
def safe_tree(node, depth, max_depth=1000):
if depth > max_depth:
raise RecursionError("Maximum recursion depth exceeded in DependencyGraph traversal")
# original DependencyGraph.tree logic simplified for illustration
children = [safe_tree(child, depth + 1, max_depth) for child in node['deps']]
return (node['rel'], children)
# FIX: replace unguarded dg.tree() with depth‑limited traversal
return safe_tree(dg.nodes[0], depth=0)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 dependencygraph.py (nltk/nltk)
nltk/parse/dependencygraph.py,nltk/parse/dependencygraph.py · DependencyGraph.tree,nltk/parse/dependencygraph.py · DependencyGraph.triples,nltk/parse/dependencygraph.py · DependencyGraph._tree
Cite this entry
@misc{vaitp:cve2026129222,
title = {{Unbounded recursion in NLTK DependencyGraph can cause RecursionError.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-129222},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-129222/}}
}
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 ::
