Junglewise Threat Intelligence

NLTK Pl196xCorpusReader quadratic ReDoS on malformed TEI blocks

Severity: low · CVSS 3.7 · Published 2026-08-27

Executive brief

NLTK is a popular Python library for natural language processing that includes corpus readers for parsing various text formats. The Pl196xCorpusReader component contains a regular expression denial of service vulnerability that can be triggered by processing specially crafted corpus files with malformed XML-like TEI blocks. An attacker can supply a corpus file with many unmatched opening tags, causing the parser to repeatedly rescan the text and consume CPU resources quadratically, potentially stalling parser threads and degrading application performance.

Technical details

The vulnerability is a ReDoS (Regular Expression Denial of Service) in the TEICorpusView.read_block method and related Pl196xCorpusReader public APIs. The root cause is the use of lazy quantifier regexes (.*?) that process entire TEI blocks from attacker-controlled corpus files. When a malformed file contains many opening XML-like tags without corresponding closing tags, each regex attempt scans toward the end of the block before failing, then restarts from the next opening tag position. This creates O(n²) behavior rather than linear parsing. The vulnerability is exploitable through public APIs like words() and tagged_words() without requiring authentication or special privileges. Attack complexity is high (requires malformed corpus files), but the attack vector is network-accessible if the application processes untrusted corpus files. The impact is availability degradation through CPU exhaustion. The fix was released in NLTK version 3.10.3, which replaced the whole-block lazy-regex parser with a linear parser or bounded tokenizer.

Affected products

  • NLTK NLTK <= 3.10.2

Timeline

  • 2026-08-27: disclosed: Advisory published to GitHub Advisory Database
  • 2026-08-12: patched: Fix released in NLTK version 3.10.3

References

Related threats