CVE-2026-129224
Unbounded recursion in NLTK CCG lexicon parser leads to RecursionError.
- CVSS 5.3
- CWE-674
- Resource Management
- Remote
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, the CCG lexicon parser's matchBrackets and augParseCategory functions recursively process nested parenthesized categories without a depth bound. An attacker-controlled lexicon string with excessive nesting can raise RecursionError through nltk.ccg.lexicon.fromstring and terminate the parse operation or request worker. This issue is fixed in version 3.10.4.
- CWE
- CWE-674
- 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
- Remote
- 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 nltk
from nltk.ccg import lexicon
def parse_lexicon(lex_str: str):
# VULNERABLE: unbounded recursion on nested parentheses
return lexicon.fromstring(lex_str)Patched code sample
import nltk
from nltk.ccg import lexicon
_MAX_NESTING = 100
def _nesting_depth(s: str) -> int:
depth = max_depth = 0
for ch in s:
if ch == '(':
depth += 1
if depth > max_depth:
max_depth = depth
elif ch == ')':
if depth > 0:
depth -= 1
return max_depth
def parse_lexicon(lex_str: str):
# FIX: limit nesting depth before parsing
if _nesting_depth(lex_str) > _MAX_NESTING:
raise ValueError("Lexicon string exceeds safe nesting depth")
return lexicon.fromstring(lex_str)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 lexicon.py (nltk/nltk)
nltk/ccg/lexicon.py,nltk/ccg/lexicon.py · augParseCategory,nltk/ccg/lexicon.py · fromstring,nltk/ccg/lexicon.py · matchBrackets,nltk/ccg/lexicon.py · nextCategory
Cite this entry
@misc{vaitp:cve2026129224,
title = {{Unbounded recursion in NLTK CCG lexicon parser 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-129224},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-129224/}}
}
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 ::
