AI and data stack advisories

Severe, 6 weeks2431Projects328

2431 severe, 6 weeks · 328 projects

NLTKGHSA-8846-p9w9-5frf

NLTK: uncontrolled recursion

NLTK

CVE-2026-129223 · Published Nov 19, 2026 · updated Nov 20, 2026

High7.5
Fix: upgrade to 3.10.4 or later
GitHub advisory

Summary

The recursive traversal engines behind WordNetCorpusReader's Synset.tree() and Synset.acyclic_tree() have no maximum call-depth safeguard and default to unlimited depth. They guard against literal cycles, but not against a long, genuinely acyclic relation chain , which exhausts the Python call stack the same way as the sibling DependencyGraph finding I reported separately. Real-world exploitability requires the host application to load a custom/foreign WordNet-format lexical resource rather than NLTK's bundled default corpus , flagging that narrower scope honestly up front since it affects severity, not validity.

Details

nltk/util.py's acyclic_depth_first() (~lines 471-541) and acyclic_branches_depth_first() (~lines 544-625) recurse once per graph edge, default to depth=-1 ("unlimited"), and guard against re-visiting the same node via an explicit traversed set (hence "acyclic") , but that set only prevents literal cycles, it never bounds how many *distinct* nodes a single call chain may pass through before returning.

Synset.tree(rel, depth=-1) (nltk/corpus/reader/wordnet.py, ~line 664) calls the recursive acyclic_branches_depth_first. There is also a third, easy-to-miss method: Synset.acyclic_tree(), a vestigial class-attribute alias for acyclic_depth_first , also genuinely recursive and vulnerable.

**Important correction to an...

Affected versions

PackageAffectedFixed in
nltk
PyPI
< 3.10.43.10.4
Details and references

### Summary The recursive traversal engines behind WordNetCorpusReader's Synset.tree() and Synset.acyclic_tree() have no maximum call-depth safeguard and default to unlimited depth. They guard against literal cycles, but not against a long, genuinely acyclic relation chain , which exhausts the Python call stack the same way as the sibling DependencyGraph finding I reported separately. Real-world exploitability requires the host application to load a custom/foreign WordNet-format lexical resource rather than NLTK's bundled default corpus , flagging that narrower scope honestly up front since it affects severity, not validity. ### Details `nltk/util.py`'s `acyclic_depth_first()` (~lines 471-541) and `acyclic_branches_depth_first()` (~lines 544-625) recurse once per graph edge, default to `depth=-1` ("unlimited"), and guard against re-visiting the same node via an explicit `traversed` set (hence "acyclic") , but that set only prevents literal cycles, it never bounds how many *distinct* nodes a single call chain may pass through before returning. `Synset.tree(rel, depth=-1)` (`nltk/corpus/reader/wordnet.py`, ~line 664) calls the recursive `acyclic_branches_depth_first`. There is also a third, easy-to-miss method: `Synset.acyclic_tree()`, a vestigial class-attribute alias for `acyclic_depth_first` , also genuinely recursive and vulnerable. **Important correction to an earlier draft of this finding:** `Synset.closure(rel, depth=-1)` (~line 609) does **not** share this bug , it actually calls `acyclic_breadth_first()`, a completely different, iterative queue/deque-based function with no recursion at all. I verified this directly: feeding both `acyclic_breadth_first` and the real `Synset.closure()` a 20,000-node genuinely-acyclic chain produces zero crash, while `acyclic_depth_first`/`acyclic_branches_depth_first`/`Synset.tree()`/`Synset.acyclic_tree()` crash reliably at ~1000-1500 nodes on the identical data. Only `.tree()` and `.acyclic_tree()` are affected , not `.closure()`. This is the same CWE-674 pattern already hardened elsewhere in the codebase (`MAX_TREE_DEPTH` in `tree/tree.py`, `MAX_DEPTH` in `featstruct.py`, `MAX_PARSE_DEPTH` in `logic.py`, `MAX_TABLEAU_DEPTH` in `tableau.py`, `MAX_DECODE_DEPTH` in `jsontags.py`, added by a commit whose message explicitly enumerates the sinks it covers) , but that hardening pass never reached `nltk/util.py` or `wordnet.py`. **Honest scope-limiting fact:** I exhaustively measured the maximum possible traversal depth across the entire official, bundled WordNet 3.0 corpus (what the overwhelming majority of real deployments use) for every relation NLTK exposes to `tree()`: hypernyms/hyponyms max depth = 18 (across all 74,374 noun synsets); `also_sees` (a relation whose graph isn't curated to stay as shallow as the taxonomy) max eccentricity = 41, largest connected component = 824 nodes; `similar_tos` max eccentricity = 1; entailments/causes/verb_groups/member_holonyms/member_meronyms/attributes all ≤ 11. Every one of these is roughly 25-60x below the ~1000-node crash threshold , there is no word or relation an attacker could pick against the standard bundled corpus that reaches anywhere near a crash. `nltk.app.wordnet_app`, NLTK's own bundled reference consumer, only ever calls `.tree()` with the safe hypernym relation. Real-world exploitability therefore strictly requires the host application to load a custom/foreign WordNet-format lexical resource , a legitimate, documented, `WordNetCorpusReader`-supported usage, but a comparatively uncommon one , and then call `.tree()`/`.acyclic_tree()` (not `.closure()`) with the default unbounded depth. ### PoC Generated a syntactically valid, minimal, real Princeton-WordNet-DB-format lexical database (`data.noun`/`index.noun`/`lexnames`/etc., with correct byte-offset-indexed synset records) encoding a 1500-node strictly-linear (genuinely acyclic) hypernym chain. Loaded it via the real, unmodified `WordNetCorpusReader(root, None)`, obta

CVSS 3.1
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
Severity from
GitHub (reviewed advisory)
Weakness
CWE-674
Also known as
CVE-2026-129223

More NLTK advisories

All NLTK