Repository navigation
Conversation
Deeply nested placeables, select expressions or call arguments recurse once per nesting level with no limit, overflowing the stack and aborting the whole process on adversarial input. Count the active nesting depth at the two constructs every recursion cycle passes through (placeables and call arguments) and report a regular ErrorKind::TooDeepNesting past a limit of 64, so the entry becomes Junk like any other syntax error. Real FTL rarely nests more than a few levels. Refs projectfluent#410
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #410
Problem
The parser recurses once per nesting level of placeables, select expressions and call arguments, with no depth limit. Deeply nested input overflows the stack, and a stack overflow aborts the whole process, so any app parsing untrusted
.ftlcan be crashed.Reproduced on current
main(0f87afb) with the issue's repro (3000 nested{, 2 MiB thread):thread has overflowed its stack/fatal runtime error: stack overflow, aborting.Fix
Count the active nesting depth in the parser and return a regular
ParserErrorpast a fixed limit, as suggested in the issue. Every recursion cycle passes throughget_placeable(placeable and select nesting) orget_call_arguments(call argument nesting), so both increment a depth counter and report a newErrorKind::TooDeepNestingonce it exceeds 64. The entry then becomes Junk like any other syntax error, with no behavior change for callers that stay under the limit — real FTL rarely nests more than a few levels.Note the counter deliberately sits in
get_placeable/get_call_argumentsrather thanget_inline_expression: a select's variants are parsed after its selector's inline expression has returned, so the select recursion never nests inline expressions.The limit of 64 matches the value cited in the issue (bevy_markup's pre-parse check) and keeps a wide margin below the observed crash depths on a 2 MiB stack (213 placeables in debug builds, 2535 in release).
Verification
fluent-syntax/tests/parser_depth.rs: 3000-deep placeable, select and call-argument nesting each parse to Junk withTooDeepNestingon a 2 MiB thread (previously: process abort); a normally nested message still parses cleanly.cargo test -p fluent-syntax— all pass (12 unit + 4 new + 39 fixture/doc tests)cargo test --workspace— all passcargo clippy --workspace --all-targets— no new warnings (the remaining ones in fluent-bundle/fluent-fallback predate this change)junk as expected, first error: Nesting of placeables, select expressions and call arguments exceeds the parser's depth limitfor all three nesting kinds instead of aborting.