Executive brief
NLTK is a Python natural language processing library widely used for corpus analysis and text processing. The XMLCorpusView component, which reads XML corpus files used for NLP tasks, has a performance flaw that allows an attacker with write access to a corpus file path to cause severe CPU exhaustion through a specially crafted malformed XML file. Processing an 8 MiB malformed file can consume ~48 CPU-seconds, potentially denying service to applications that rely on automated corpus processing.
Technical details
The vulnerability is an algorithmic inefficiency in XMLCorpusView._read_xml_fragment() (nltk/corpus/reader/xmldocs.py, lines 261–308). The function reads XML corpus files in 1 KiB blocks, appending each block to a `fragment` string, then calls `_VALID_XML_RE.match(fragment)` to validate the accumulated buffer on every iteration. Because the regex match rescans the entire accumulated fragment from the beginning each iteration, total work grows O(n²) rather than O(n). For a payload of a single `<` followed by (N-1) `a` bytes, the unterminated tag prevents regex match success and `fragment.rfind("<")` returns 0, bypassing the backtrack optimization. The only exit is EOF after consuming all N bytes. This affects all readers derived from XMLCorpusView (BNCCorpusReader, NPSChatCorpusReader, SemcorCorpusReader, MTECorpusReader, NKJPCorpusReader, FrameNetCorpusReader, VerbNetCorpusReader) but not XMLCorpusReader.xml() which uses defusedxml.safe_parse(). Exploitation requires only write access to a corpus file path the reader will open; no authentication or special privileges are needed. A patch (NLTK 3.10.3+) is available that eliminates quadratic rescanning via incremental parsing or bounded accumulation.
Affected products
- NLTK Project NLTK 3.10.2 and earlier; including 3.9.4, 3.10.0; potentially all versions since 2007 introduction of XMLCorpusView
Timeline
- 2026-09-02: disclosed: Advisory published to GitHub Advisory Database and CVE
- 2026-09-02: patched: NLTK 3.10.3 released with fix (commit 7808692)