GitHub advisory · PyPI
NLTK: Uncontrolled recursion in DependencyGraph traversal causes denial of service via deep dependency chains
Description
The dependency-graph traversal helpers recurse over dependency links without any depth
bound or visited set. DependencyGraph._tree (nltk/parse/dependencygraph.py:404)
recurses once per dependency link, triples (nltk/parse/dependencygraph.py:432) is a
recursive generator, and get_cycle_path (nltk/parse/dependencygraph.py:520) recurses
over dependencies. The neighbouring contains_cycle method was deliberately rewritten as
an iterative depth-first search, but these sibling helpers on the public traversal path
were left recursive with no depth counter.
An application that parses an untrusted CoNLL/Malt-TAB dependency structure and then walks
it via tree() or triples() aborts with an unhandled RecursionError, terminating the
affected operation or request worker (denial of service, CWE-674). The recursion is pure
Python, so the result is a catchable RecursionError, not memory corruption or code
execution. Confidentiality and integrity are unaffected. get_cycle_path additionally
lacks a visited set and will not terminate on a genuine cycle.
DependencyGraph(conll_str) from attacker-supplied text
where token k's head is token k+1, forming a linear dependency chain of length N.
Graph construction (_parse) is iterative and completes without error.DependencyGraph.tree()
(nltk/parse/dependencygraph.py:408), which invokes _tree(root)._tree recurses once per chain link with no depth guard and no visited set, consuming
one stack frame per link (the list comprehension costs roughly two frames per level).RecursionError propagates out of the public API. triples() fails the same way.Against the shipped source at the default recursion limit, a chain of length 5 walks
cleanly through tree(), while a chain of length…
Manual fix · PyPI
pip install --upgrade "nltk>=3.10.4"Sources