Executive brief
NLTK is a widely-used natural language processing library. Its feature-structure parser, used in NLP applications and grammar tools, lacks protection against deeply nested input. An attacker can send a small malicious grammar string (~700 bytes) that causes the application to crash instantly with an unhandled exception. The impact ranges from request failures in web applications to complete process termination in single-threaded workers.
Technical details
The vulnerability is a classic uncontrolled recursion issue (CWE-674) in nltk.featstruct.FeatStructReader. The recursive call chain (_read_partial → _read_value → read_value → read_fstruct_value → read_partial) has no depth counter or MAX_PARSE_DEPTH guard. When deeply nested feature structures like "[a=" repeated 167 times are provided, the parser exceeds Python's recursion limit and raises an unhandled RecursionError instead of the library's normal ValueError. The PoC crashes in ~2ms with just 669 bytes. The parser is reachable via FeatStruct(str) and FeatureGrammar.fromstring(), affecting any application that processes user-supplied grammars. The fix (adding a MAX_PARSE_DEPTH constant and depth check) was already implemented in nltk/sem/logic.py but missing from featstruct.py. Patched in NLTK 3.10.3.
Affected products
- NLTK Project NLTK <= 3.10.2
Timeline
- 2026-08-12: disclosed
- 2026-09-02: advisory: GitHub Security Advisory published
- 2026-09-02: patched: Fix released in NLTK 3.10.3
References
- https://api.github.com/users/JoshgunAbdullayev
- https://github.com/JoshgunAbdullayev
- https://api.github.com/users/JoshgunAbdullayev/gists%7B/gist_id%7D
- https://api.github.com/users/JoshgunAbdullayev/repos
- https://avatars.githubusercontent.com/u/128043503?v=4
- https://api.github.com/users/JoshgunAbdullayev/events%7B/privacy%7D