Skip to content
Medium 5.3

NLTK: Uncontrolled recursion in Tree.fromlist causes denial of service via deeply nested list input

CVE-2026-129227 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

Tree.fromlist (nltk/tree/tree.py:767) converts a nested list into a Tree by recursing
once per nesting level (nltk/tree/tree.py:780) with no depth bound — its only validation
is type(l) == list and len(l) > 0. The sibling constructor Tree.fromstring was hardened
with a MAX_TREE_DEPTH cap (nltk/tree/tree.py:31,695) that rejects adversarially deep
input with a bounded ValueError, but that guard was not applied to fromlist, which
builds Tree objects identically.

Impact

An application that builds a Tree from an attacker-controlled nested list — for example
Tree.fromlist(json.loads(untrusted)) — aborts with an unhandled RecursionError,
terminating the affected operation or request worker (denial of service, CWE-674). Any
later recursive traversal of an over-deep tree (height, pformat, equality) fails the
same way. The recursion is pure Python, yielding a catchable RecursionError rather than
memory corruption or code execution. Confidentiality and integrity are unaffected.

Attack Chain

  1. The application obtains an attacker-controlled deeply nested list, typically by decoding
    an untrusted JSON payload, and calls nltk.tree.Tree.fromlist(l).
  2. fromlist checks only that the argument is a non-empty list; it applies no depth cap.
  3. fromlist recurses once per nesting level, consuming call-stack frames; the
    MAX_TREE_DEPTH guard used by fromstring is never invoked on this path.
  4. Once the nesting depth exceeds the i…

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