Infinite loop Affecting nltk package, versions [3.6.7,3.10.4)


Severity

Recommended
0.0
high
0
10

CVSS assessment by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of Concept
EPSS
0.4% (37th 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-22733146
  • published22 Nov 2026
  • disclosed19 Nov 2026
  • credithaoxiang Yan

Introduced: 19 Nov 2026

NewCVE-2026-128140  (opens in a new tab)
CWE-835  (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 Infinite loop via Downloader._update_index in nltk/downloader.py when processing a collection index containing self-referencing or mutually-referencing <collection> entries. After _update_index replaces each <item ref="…"> string with the live Collection or Package object, it computes each collection's recursive package closure using a breadth-first walk that appends to the list it is iterating (for child in queue: queue.extend(child.children)) with no visited set and no cycle detection. A cyclic index - where a collection references itself or participates in a mutual reference cycle - causes the queue to grow without bound, spinning the CPU at 100% and consuming memory until the process is killed or the host runs out of memory. Every downloader entry point (download(), info(), packages(), collections(), list(), status()) funnels through _update_index and is permanently blocked.

PoC

The self-checking reproduction script embedded below runs the attack against a file://-hosted index (no network server needed; the hardened nltk.pathsec.urlopen accepts local file:// URLs) and a matching acyclic control index, in separate child processes under an address-space cap (RLIMIT_AS). That is the key to demonstrating the vulnerability safely and precisely: the control process completes under the cap, while the attack process — the same function, the same caller, the same finite 2-entry index — cannot finish and is aborted by MemoryError at queue.extend(child.children), proving both the hang (the function never returns) and the unbounded memory growth (a 2-entry index growing until the address-space cap is exhausted). Without the cap the loop simply runs forever.

Scope note: dynamically verified on the released 3.6.7, 3.9.2, and 3.10.3 wheels and on develop 6818767b9. 3.6.0–3.6.6 share the identical BFS code path (verified statically at the tag) but were not run; the downloader tool predates 3.6 and earlier releases were not assessed.

Environment for the recorded run: CPython 3.10.12 on Linux; the script defaults to a 512 MiB address-space cap per child and a 60 s hard timeout. All four version runs pass 4/4 checks.

Live transcript (recorded run on the nltk 3.10.3 wheel; the 3.6.7, 3.9.2, and develop 6818767b9 runs produce the same 4/4 result, differing only in the downloader.py line number in the traceback — 987, 972, and 1305 respectively — and the elapsed time):

[PASS] precondition: cyclic index has a self-referencing <collection>  (ref='a' inside <collection id='a'>)
[PASS] precondition: acyclic control index references only packages
[control] returned rc=0 in 0.2s
[PASS] control: Downloader.packages() returned (no hang)
[PASS] control: _packages parsed = ['p1']
[PASS] control: collection 'a' closure = ['p1'] (finite, as documented)
[PASS] control: acyclic index completes and yields the documented finite closure  (rc=0)
[attack] rc=1 after 6.6s
[attack] entering Downloader.packages() on the self-referencing index ...
Traceback (most recent call last):
  File "<string>", line 38, in <module>
  File "nltk/downloader.py", line 627, in packages
    self._update_index()
  File "nltk/downloader.py", line 1305, in _update_index
    queue.extend(child.children)
MemoryError
[PASS] attack: self-referencing index is not completed -- process aborted by the 512 MiB address-space cap (unbounded queue growth)  (rc=1, MemoryError)
nltk under test: 3.10.3
RESULT 4/4 checks passed, 0 failed

The malicious index is exactly:

<index>
  <packages>
    <package id="p1" name="Sample corpus" subdir="corpora/p1"
             url="http://example.invalid/p1.zip" unzip="0" size="0" unzipped_size="0"/>
  </packages>
  <collections>
    <collection id="a" name="Cyclic collection">
      <item ref="a"/>
      <item ref="p1"/>
    </collection>
  </collections>
</index>

Note: The PoC runs on CPython 3.10.12 on Linux, using a file://-hosted index and separate child processes under a 512 MiB RLIMIT_AS address-space cap with a 60-second hard timeout.

CVSS Base Scores

version 4.0
version 3.1