# NLTK quadratic CPU exhaustion in XMLCorpusView._read_xml_fragment()

Source: https://junglewise.ai/threats/nltk-quadratic-cpu-exhaustion-in-xmlcorpusview-read-xml-fragment-439bc4da  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2026-08-27. Updated: 2026-09-25  
License: CC BY 4.0 with a link back

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

NLTK's XML corpus reader rescans accumulated XML data repeatedly while processing large files, causing CPU consumption to grow quadratically with file size. An attacker who can supply a malformed XML corpus file can trigger severe CPU exhaustion and deny service to applications using affected corpus readers like BNCCorpusReader, with an 8 MB file consuming ~48 seconds of CPU on typical hardware.

Technologies: [nltk (PyPI)](https://junglewise.ai/threats/technologies/nltk). Vendors: [PyPI](https://junglewise.ai/threats/vendors/pypi).

## Quick answers

**Is This vulnerability exploited in the wild?** No. Junglewise Threat Intelligence has no report of This vulnerability being exploited in the wild.

**How severe is This vulnerability?** Low severity, with a CVSS score of 3.7, published 27 August 2026.

**Which products and versions are affected?** nltk (PyPI) <= 3.10.2.

**Is there a fix for This vulnerability?** A patch was published on 2026: Fixed in NLTK 3.10.3 or later Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**How is This vulnerability attacked?** It is attacked over the network, in a software library.

**Am I affected?** Check whether you run nltk (PyPI) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

## Technical details

The vulnerability exists in XMLCorpusView._read_xml_fragment() (nltk/corpus/reader/xmldocs.py, lines 261–308), which reads XML corpus files in 1 KiB blocks and accumulates them into a fragment buffer. On each iteration, the function calls _VALID_XML_RE.match() on the entire accumulated buffer, causing O(N²) behavior where N is file size in KiB blocks. A malformed XML payload consisting of an unterminated opening tag (e.g., &lt; followed by N bytes of 'a') will never match valid XML, forcing the loop to consume the entire file before EOF terminates it. Affected readers include BNCCorpusReader, NPSChatCorpusReader, SemcorCorpusReader, MTECorpusReader, NKJPCorpusReader, FrameNetCorpusReader, and VerbNetCorpusReader. The attack requires only write access to a path the reader will process; no authentication or special privileges are needed. NLTK 3.10.3 and later patch this issue; earlier versions including 3.9.4, 3.10.0, and 3.10.2 are vulnerable.

## Affected products

- NLTK Project NLTK <= 3.10.2

## Timeline

- 2026-08-12: disclosed: Original advisory GHSA-vp2x-qp44-57v7 published
- 2026: patched: Fixed in NLTK 3.10.3 or later
- 2026-08-27: advisory: Duplicate advisory GHSA-hqv3-xm29-p9hq published (later withdrawn)

## References

- [https://github.com/nltk/nltk/security/advisories/GHSA-vp2x-qp44-57v7](https://github.com/nltk/nltk/security/advisories/GHSA-vp2x-qp44-57v7)
- [https://www.vulncheck.com/advisories/nltk-before-3.10.3-quadratic-cpu-exhaustion-via-xmlcorpusview](https://www.vulncheck.com/advisories/nltk-before-3.10.3-quadratic-cpu-exhaustion-via-xmlcorpusview)

## Related threats

- [NLTK WekaClassifier path traversal in model validation](https://junglewise.ai/threats/cve-2026-109956-nltk-through-3-10-3-contains-a-path-traversal-vulnerability-in)
- [NLTK RecursiveDescentParser uncontrolled recursion denial of service](https://junglewise.ai/threats/cve-2026-12876-nltk-recursivedescentparser-uncontrolled-recursion-denial-of)
- [NLTK tgrep regular expression denial of service](https://junglewise.ai/threats/nltk-tgrep-regular-expression-denial-of-service-02fca1b2)
- [NLTK Downloader hardlink filesystem containment bypass](https://junglewise.ai/threats/nltk-downloader-hardlink-filesystem-containment-bypass-522cb97d)
- [NLTK Pl196xCorpusReader quadratic ReDoS on malformed TEI blocks](https://junglewise.ai/threats/nltk-pl196xcorpusreader-quadratic-redos-on-malformed-tei-blocks-8473e6ef)
