medium

CVE-2026-81725

PyPI · nltk

Summary

NLTK: Pl196xCorpusReader has quadratic ReDoS on malformed TEI blocks

Severity
medium
EPSS
0.2% (p14)
CWE
CWE-400, CWE-1333
Also known as
GHSA-8mpw-7fpc-4gqj
Published
2026-09-08
Updated
2026-09-08

Advisory details

Summary

Pl196xCorpusReader still parses whole TEI blocks with multiple lazy regexes over attacker-controlled text. A malformed file with many opening tags and no matching closing tags forces repeated rescans and produces quadratic CPU growth in public reader APIs.

Details

The parser uses regexes for paragraphs, sentences, and word tags across the whole <text> block. When the attacker supplies many unmatched opening tags, each attempt scans toward the end of the block and fails, then restarts from the next opening tag. There is near four-times runtime growth each time the number of malformed <p> tags doubled, through normal public calls such as words() and tagged_words().

PoC

Preconditions

Steps

  1. Create a corpus file with a valid header followed by a <text> block that contains many opening tags and no matching closing tags.
  2. Instantiate Pl196xCorpusReader on that corpus.
  3. Call words() or tagged_words() and measure elapsed time as the malformed tag count doubles.
  4. Observe near quadratic growth instead of near-linear behavior.

Minimal reproducible excerpt

size=1000 0.014s
size=2000 0.057s
size=4000 0.231s
size=8000 0.927s

Impact

A consumer that accepts attacker-influenced corpus files can be forced into heavy CPU use and parser-thread stalling before the application concludes the input contains no valid content.

Remediation

Replace the whole-block lazy-regex parser with a linear parser or bounded tokenizer, and add regression tests that assert near-linear behavior on malformed inputs with many unmatched tags.

References

Related advisories

Is your project exposed to this? Stateward checks every dependency on every pull request and flags it only if your code actually reaches it.

Check my repo

Summarize with AI

ChatGPTClaudePerplexity

Sources: CISA KEV (public domain), OSV.dev & GitHub Advisory Database (CC-BY-4.0), FIRST EPSS, NVD/CWE (public domain). Served live from the Stateward advisory database.