NLTK WordNet tree methods can run out of memory with deep relation chains

HighSE Fix-First Score 43/100CVE-2026-129223SE-AIV-01439Denial of service and resource exhaustionAI softwareMade public 20 Nov 2026

Download as PDF

What this means

An application using NLTK to process a custom WordNet dictionary could crash or become unresponsive. The crash happens when the application calls tree() or acyclic_tree() on a deep set of related words. This stops the service until it is restarted.

SecurityElites Manager Brief: the decision in one minute

NLTK has two methods that can crash when given a large chain of word relations. The risk is real only if your application loads a custom dictionary rather than NLTK's built-in one. Update NLTK to fix it.

SecurityElites Fix-First Score43 of 100
Our own ranking of what to fix first. Real attacks count most, then the chance of attack, then severity.
SecurityElites fix windowWithin 30 days
High severity. This is our suggestion from common practice; your own policy comes first.
Who should own the fixThe team that manages Python packages and natural language processing pipelines.
Likely effortAbout 15 minutes: update NLTK to version 3.10.4 and restart the application. Longer if you need to test with your own custom dictionaries first.

Questions to ask your team or supplier

  • Do we load any custom WordNet dictionaries or external lexical resources, or do we only use NLTK's bundled English dictionary?
  • Which of our applications and services call Synset.tree() or Synset.acyclic_tree(), and what happens if they crash?
  • If we cannot upgrade immediately, can we replace tree() calls with closure() or add a depth parameter to limit recursion?

Message you can forward to the owning team

Security notice: NLTK WordNet tree methods can run out of memory with deep relation chains (CVE-2026-129223)

Severity: High
SecurityElites Fix-First Score: 43 of 100
SecurityElites fix window: Within 30 days
Action: upgrade to nltk 3.10.4 or later.
What we need from you: confirm whether we run this software, who owns it, and the date it will be fixed.
Full guide: https://securityelites.com/ai-vulnerabilities/cve-2026-129223-nltk-wordnet-tree-methods-can-run-out-of-memory/
Source: SecurityElites AI Vulnerabilities Database, record SE-AIV-01439

What is at stake in your AI setup

  • Training data or retrieval data: a custom WordNet or knowledge base loaded for model training or retrieval could cause the service to crash before data is used
  • Tools and systems the agent is connected to: if an AI agent uses NLTK to query a custom dictionary, it could crash the agent and stop processing requests
  • Compute bill: a crash loop where the service restarts repeatedly can waste compute resources and increase cloud bills

Map where your company uses AI

Who is exposed

  • Teams running NLTK applications that load custom WordNet dictionaries from external or untrusted sources
  • NLP services that call Synset.tree() or Synset.acyclic_tree() on user-supplied data
  • Development and staging environments where NLTK is used to process arbitrary dictionaries
  • Teams using only NLTK's built-in English dictionary are not at risk

Upgrades you need

SoftwareAffected versionsMove to
nltk
PyPI
Every version before 3.10.43.10.4 or later

Am I affected?

Enter the version you run. Nothing you type is stored.

SecurityElites Developer Brief: the technical picture

Is it being attackedNo known attacks and no public attack code when CISA last reviewed it
Where the attacker must beAnywhere that can reach it over a network, including the internet if it is exposed
Account neededNone. No login is needed
Does a person have to do somethingNo. It works without anyone clicking or opening anything
How hard it is to doEasy. It works reliably once the attacker can reach it
Risk of: data being readNone
Risk of: data or settings being changedNone
Risk of: the service being taken downHigh
Can attackers automate it at scaleYes, according to CISA
How much control an attacker gainsPartial control, according to CISA

Read from the official severity rating: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H

Kind of coding mistake

  • CWE-674

Where it sits in the standards

OWASP Top 10 for LLM Applications 2025: LLM10 Unbounded Consumption

If you cannot upgrade today

  • Avoid calling `.tree()` and `.acyclic_tree()` on untrusted or deeply nested WordNet data until you upgrade; use `.closure()` as a safer alternative if it meets your needs.

Signs it may already have been used against you

  • Search application logs and error trackers for `RecursionError` or `maximum recursion depth exceeded` messages
  • Look for memory usage spikes or out-of-memory kills coinciding with calls to `.tree()` or `.acyclic_tree()`
  • Check whether crashes happen when the application processes custom or unusual WordNet dictionaries
  • Monitor for service timeouts or hangs in endpoints or jobs that call these methods

Log searches to start from

Find RecursionError in NLTK-related logs (adapt source and fields to your environment)Splunk

source=app_logs (RecursionError OR "maximum recursion") nltk

Find spikes in memory or crashes tied to tree methods (adapt index and fields)Elastic

message:RecursionError AND (message:tree OR message:acyclic_tree)

Written with AI as a starting point. Review them and change the index and field names to match your own logs before you rely on the result.

SecurityElites Fix Guide: step by step

  1. Find where NLTK is installed and what version you haveList all Python environments where NLTK is used: virtual environments, containers, cloud functions. Check the version in each with `pip show nltk` or `python -c "import nltk; print(nltk.__version__)"`.
  2. Search your code for calls to tree() and acyclic_tree()Use grep or your IDE to find all calls to `.tree(` and `.acyclic_tree(` on Synset objects. Note which applications and scripts use these methods.
  3. Check whether your application loads custom WordNet dictionariesReview your application's setup code and configuration files. If it only uses NLTK's default bundled English dictionary (loaded via `nltk.corpus.wordnet`), the risk is lower. If it loads dictionaries from files, URLs, or user input, the risk is higher.
  4. Update NLTK to version 3.10.4 or laterIn each Python environment, run `pip install --upgrade nltk>=3.10.4`. If you use a requirements file or lock file, update nltk to 3.10.4 and reinstall dependencies.
  5. Restart all services and jobs that use NLTKRestart web services, batch jobs, cloud functions, and any long-running processes that import NLTK. Confirm they start without errors in logs.
  6. Test that tree() methods still work on your dataIf your application calls `.tree()` or `.acyclic_tree()`, run a quick test on a small sample of your actual dictionaries. Confirm the methods return results and do not crash.
  7. Review logs for crashes before the updateSearch application logs and error tracking systems for RecursionError, stack overflow, or out-of-memory crashes in the past month. If you find any tied to tree() calls, document them as evidence of past exposure.
  8. If you load untrusted dictionaries, add a depth limit as a safeguardEven with NLTK 3.10.4, consider validating custom WordNet files for reasonably short relation chains before loading them. Set a maximum depth parameter in tree() calls to a sensible limit for your use case (for example, `tree(depth=20)` instead of the default unlimited depth).

How to confirm it is fixed: Run a test call to `.tree()` on your application's actual WordNet data after upgrading; it should return results without crashing or hanging.

SecurityElites Quick Fixes: copy and paste

Upgrade nltk with pipupgrade

pip install --upgrade "nltk>=3.10.4"
pip show nltk | grep Version

Pin it in requirements.txtupgrade

nltk>=3.10.4

Check NLTK version installedfor this issue

pip show nltk | grep Version

Find calls to tree methods in Python codefor this issue

grep -r '\.tree(\|\.acyclic_tree(' --include='*.py' .

Safe way to call tree() with a depth limitfor this issue

# Instead of: synset.tree()
# Use: synset.tree(depth=20)  # Limit to 20 levels deep

Rate and size limits with nginxgeneral hardening

limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;

server {
    location /api/ {
        limit_req zone=api burst=20 nodelay;
        client_max_body_size 2m;
    }
}

Test in a non-production environment first. General hardening examples use placeholder names and ports; change them to match your setup.

Let your AI coding assistant do the upgrade

Paste this into the coding assistant you already use, inside the project. It checks first and asks before it changes anything.

Instruction for your coding assistant

You are helping me fix a security vulnerability (CVE-2026-129223) in this project.\n\n1. Search the whole repository, including lock files, container files and CI configuration, for these packages and list every place they are pinned or installed:\n   - nltk (PyPI): must be 3.10.4 or later
2. Tell me which version we use now and whether it is affected. Stop and ask me before changing anything.
3. After I agree, raise each one to the safe version, update the lock files, and keep every other dependency as it is.
4. Run the tests and tell me what failed.
5. Give me a short summary of the files you changed that I can put in the pull request.

SecurityElites Incident Drill: could your team handle this?

Four questions to ask in your next team meeting. If any has no clear answer, that is the gap to close.

What is the difference between being at risk and being safe from this bug?A good answer: You are at risk if your application calls tree() or acyclic_tree() on a custom WordNet dictionary with long relation chains; you are safe if you only use NLTK's default bundled dictionary.
How do you know if your code is affected?A good answer: Search your code for `.tree(` and `.acyclic_tree(` method calls, and check whether your application loads custom or external WordNet files.
What should you do immediately?A good answer: Update NLTK to 3.10.4, restart services, and test that tree methods still work on your actual data.
What is a safe alternative if you cannot upgrade?A good answer: Use Synset.closure() instead of tree() if possible, because closure is iterative and does not have this bug.

Run a full timed drill with your team

Ticket for your backlog

Paste into Jira, GitHub Issues or any tracker that reads Markdown.

Ready-made ticket

## NLTK WordNet tree methods can run out of memory with deep relation chains (CVE-2026-129223)

**Severity:** High  |  **SE Fix-First Score:** 43/100  |  **Fix window:** Within 30 days
**Record:** SE-AIV-01439 https://securityelites.com/ai-vulnerabilities/cve-2026-129223-nltk-wordnet-tree-methods-can-run-out-of-memory/

### Why this matters
An application using NLTK to process a custom WordNet dictionary could crash or become unresponsive. The crash happens when the application calls tree() or acyclic_tree() on a deep set of related words. This stops the service until it is restarted.

### What to do
1. Find where NLTK is installed and what version you have
2. Search your code for calls to tree() and acyclic_tree()
3. Check whether your application loads custom WordNet dictionaries
4. Update NLTK to version 3.10.4 or later
5. Restart all services and jobs that use NLTK
6. Test that tree() methods still work on your data
7. Review logs for crashes before the update
8. If you load untrusted dictionaries, add a depth limit as a safeguard

Full steps: https://securityelites.com/ai-vulnerabilities/cve-2026-129223-nltk-wordnet-tree-methods-can-run-out-of-memory/

### Done when
- [ ] nltk is at 3.10.4 or later everywhere it is installed
- [ ] Lock files, container images and CI configuration are updated
- [ ] Run a test call to `.tree()` on your application's actual WordNet data after upgrading; it should return results without crashing or hanging.
- [ ] Logs were checked for signs of earlier use

SecurityElites Fix Tracker

Record who owns this fix, the date it is due and when it is done, and see everything still open in one list. Free with a SecurityElites account.

Sign in to track this fix

Change history

  • 19 Nov 2026: Made public
  • 1 Dec 2026: Published

Official record

### 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)`, obtained a rea

Weakness type: CWE-674

Use this record in your own tools

Get this record as JSON

curl https://securityelites.com/wp-json/se-aivd/v1/vulns/CVE-2026-129223

For scanners and pipelines: OSV format · CycloneDX format · API guide · Email alerts · Fix tracker

The plain-language sections were written with AI from the official record, and the upgrade versions come directly from the official data. Last updated 1 Dec 2026. Read the vendor advisory before changing a production system.