GHSA-53pg-5qp8-mhvr: NLTK: Uncontrolled recursion in WordNet Synset hypernym walkers (max_depth/min_depth/hypernym_paths/hypernym_distances) causes DoS
- Source:
- OSV.dev
- Published:
- Fetched:
- Updated:
- Affects:
- nltk
https://osv.dev/vulnerability/GHSA-53pg-5qp8-mhvr ↗
NLTK: Uncontrolled recursion in WordNet Synset hypernym walkers (max_depth/min_depth/hypernym_paths/hypernym_distances) causes DoS ## Summary Four hypernym-walking methods on the WordNet `Synset` class in `nltk/corpus/reader/wordnet.py` (`max_depth`, `min_depth`, `hypernym_paths`, and `hypernym_distances`) traverse the hypernym pointer graph by direct recursion with no visited-node set and no depth cap. WordNet `data. ` file content is untrusted corpus input in NLTK, the same trust boundary the project already treats as attacker-controlled across its corpus-content hardening work. When the parsed hypernym graph contains a cycle, or a chain deeper than the interpreter recursion limit, these methods recurse without bound and raise an uncaught `RecursionError`, aborting the traversal and any worker that does not catch it. No special privileges are needed; the victim only has to load an attacker-supplied corpus and call any of several shipped public methods that reach these walkers. ## Root Cause `Synset.max_depth` computes `1 + max(h.max_depth() for h in hypernyms)` and only assigns its `_max_depth` memo after that recursive expression fully returns. Because Python evaluates the right-hand side completely before binding the left-hand side, the memo is never set on a node that is still on the recursion stack, so a cyclic graph re-enters the same not-yet-memoized node indefinitely. `min_depth`, `hypernym_paths`, and `hypernym_distances` follow the same recursive descent with no cycle detection. The security invariant that graph traversal over untrusted corpus data must terminate is violated: the pointer offsets parsed from the data file are stored verbatim with no graph-shape validation, so the attacker controls the graph topology. The sibling walkers in the same class (`closure`, `tree`, `_shortest_hypernym_paths`) were hardened with acyclic/visited guards, which shows cyclic hypernym graphs are an in-scope threat that these four methods simply were not converted to handle. ```text Affected functions in nltk/corpus/reader/wordnet.py: Synset.max_depth (nltk/corpus/reader/wordnet.py:550) Synset.min_depth (nltk/corpus/reader/wordnet.py:564) Synset.hypernym_paths (nltk/corpus/reader/wordnet.py:666) Synset.hypernym_distances (nltk/corpus/reader/wordnet.py:768) Untrusted pointer stored at nltk/corpus/reader/wordnet.py:1694 Re-entry edge: hypernyms() (:138) -> _related('@') (:1103) -> synset_from_pos_and_offset (:1104) ``` ## Impact An attacker who can supply a WordNet `data. ` corpus file that the victim loads (for example a downloaded, mirrored, or user-provided WordNet corpus) can construct a hypernym pointer graph that is cyclic or deeper than the recursion limit. When the application then calls any hypernym-depth or path method, the walker recurses without bound and raises an uncaught `RecursionError`, terminating the current traversal and any request or worker process that does not handle it. Under a raised or removed recursion limit, unbounded recursion can instead exhaust the native stack and abort the process. The impact is availabil Affected: PyPI:nltk Fixed in: 3.10.4 References: https://github.com/nltk/nltk/security/advisories/GHSA-53pg-5qp8-mhvr https://nvd.nist.gov/vuln/detail/CVE-2026-129230 https://github.com/nltk/nltk/pull/3895 https://github.com/nltk/nltk/commit/34adf1ee425b5c817d2a88c674bac68672e3ab26 https://github.com/nltk/nltk https://github.com/nltk/nltk/releases/tag/v3.10.4