Browse / AI Framework and Platform Flaws / CVE-2026-81724
NLTK: Uncontrolled recursion in nltk.featstruct.FeatStructReader causes unhandled RecursionError (DoS) via deeply nested feature-structure input
- Class
- AI Framework and Platform Flaws (filed by a model that read the advisory)
- Technique
- Denial of service
- Affected
- nltk (PyPI)
- CVSS
- CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L
- EPSS
- 0.5% chance of exploitation in 30 days
How it works, in short
The featstruct parser recurses on nested brackets with no depth limit, so a short, deeply nested string exhausts the stack and raises an uncaught RecursionError. (Our summary, written by a model. The source text is below.)
Details
Summary
nltk.featstruct.FeatStructReader (used by FeatStruct(str) and by FeatureGrammar.fromstring()) parses feature-structure strings such as [a=1] with a recursive-descent parser that has no nesting-depth limit. A small, trivially-crafted input (~700 bytes) with deeply nested brackets drives the parser past Python's recursion limit and raises an unhandled RecursionError instead of the library's normal, catchable ValueError/LogicalExpressionException. Any application that parses user-supplied feature-structure or feature-grammar text (e.g. NLP teaching tools, grammar "playgrounds", unification-grammar-based NLU pipelines) can be crashed by an unauthenticated input with no special privileges. This is a Denial of Service issue (CWE-674, Uncontrolled Recursion), not a memory-safety or code-execution issue.
This appears to be the same bug class as two issues already fixed elsewhere in the codebase — nltk/jsontags.py (JSONTaggedDecoder.decode_obj, guarded by MAX_DECODE_DEPTH = 200) and nltk/sem/logic.py (LogicParser, guarded by MAX_PARSE_DEPTH = 200) — but nltk/featstruct.py does not have an equivalent guard.
Details
The recursive call chain (current develop branch, nltk/featstruct.py):
FeatStructReader.fromstring()([featstruct.py:2184](nltk/featstruct.py#L2184)) callsread_partial()→_read_partial()([featstruct.py:2250](nltk/featstruct.py#L2250))._read_partial()dispatches to_read_partial_featdict(), which calls_read_value()([featstruct.py:2436](nltk/featstruct.py#L2436)) for each feature's value._read_value()callsread_value()([featstruct.py:2442](nltk/featstruct.py#L2442)), which matches the value againstVALUE_HANDLERS([featstruct.py:2478](nltk/featstruct.py#L2478)).- If the value itself starts with
[(a nested feature structure), the matched handler isread_fstruct_value([featstruct.py:2479](nltk/featstruct.py#L2479), defined at [featstruct.py:2495](nltk/featstruct.py#L2495)):