NLTK XML parser can exhaust CPU on deeply nested corpus files

  • NLTK
  • denial-of-service
  • XML
  • CPU exhaustion

Deeply nested XML tags trigger quadratic computational complexity

Attackers who can supply untrusted corpus XML can cause denial of service

Multiple corpus readers are affected by the inefficient parsing

NLTK reported a vulnerability in XMLCorpusView.read_block, a method used to read XML corpus data. Deeply nested XML can make the method consume excessive CPU and cause a denial of service in applications that process attacker-influenced corpus files.

The method reconstructs the path from the XML root to the current element on every start tag while searching for a match. Because that path grows with nesting depth, repeatedly rebuilding it creates quadratic work: a file with roughly 200 KB of crafted XML can occupy a single CPU core for several seconds, according to the report.

The issue affects applications that pass untrusted or attacker-influenced XML corpus data to subclasses of XMLCorpusView. NLTK classifies the vulnerability as CWE-407 and CWE-400; the reported impact is on service availability, not confidentiality or integrity. The supplied advisory lists versions through 3.10.3 as affected and 3.10.4 as patched.