Skip to content
Medium 5.3

NLTK: Uncontrolled recursion in CCG lexicon parser causes denial of service via deeply nested category input

CVE-2026-129224 First seen on SecPulse

Affected packages

PackageAffected → Fixed
nltknltk —
PyPInltk
< 3.10.4→ 3.10.4
pipnltk
< 3.10.4→ 3.10.4

Fix status by distribution

Records published by each distribution for this CVE. Fixed versions differ by release; check each link.

Original description The description as published by the source.

Root Cause

The CCG lexicon parser recurses on nested parenthesised categories without any depth
bound. matchBrackets (nltk/ccg/lexicon.py:154) calls itself once per nested (, and
augParseCategory (nltk/ccg/lexicon.py:228,242) recurses once per bracketed
sub-category. Neither function tracks recursion depth nor checks
sys.getrecursionlimit(), and the public entry point fromstring
(nltk/ccg/lexicon.py:252, also re-exported via nltk.ccg.chart.fromstring) applies no
length or nesting cap before handing the text to the parser.

Impact

An application that parses an untrusted lexicon string aborts with an unhandled
RecursionError, terminating the affected parse operation or request worker
(denial of service, CWE-674). The recursion is pure Python, so CPython raises a catchable
RecursionError rather than crashing the process; there is no memory-corruption or
code-execution primitive. Confidentiality and integrity are unaffected. Plausibly, a
service that does not wrap the parse in a handler will surface the error to the caller and
drop the in-flight request.

Attack Chain

  1. The application calls nltk.ccg.lexicon.fromstring(lex_str) with attacker-supplied
    text such as ":- S\nw => " + "(" * 2000 + "S" + ")" * 2000 + "\n".
  2. fromstring splits the input into lines; LEX_RE/RHS_RE
    (nltk/ccg/lexicon.py:275-276) match and route the parenthesised category into
    augParseCategory (nltk/ccg/lexicon.py:277) with no depth or length guard.
    3.…

Source: CVE.org (CVE Program・cvelistV5) NVD GitHub Advisory

References

We use cookies for analytics and ad measurement. This setting applies to all Game co., Ltd. sites. Details