Repository navigation
Description
Summary
Two parts of the i18n pipeline have no explicit depth limit. Both read only the app's own translation files (messages, messages_file, catalog .ftl files), so this is extra safety rather than a fix for any input users control. A clear error at a fixed depth is better than a slow startup or a crash.
1. Message references
When one message refers to another ({ other-message } or a term), the i18n compiler follows the chain. Its time grows about with the cube of the chain depth: a chain about 300 levels deep takes about 7.8 s to compile. There is no depth limit.
Proposal: limit the depth of a reference chain (a few dozen levels is far more than any real catalog needs) and fail with an error that names the message, its file and line, and the limit. Also look at whether the compile can be made linear, for example by computing each message's result once and reusing it.
2. Nested placeables
The Fluent parser we use (fluent-syntax, pinned in the root Cargo.toml) parses nested placeables recursively. At about 20,000 levels, such as { { { ... } } }, it runs out of stack and the process stops.
Proposal: count the nesting before handing the source to fluent-syntax, without recursion, as crates/python_safe_eval/src/nesting.rs does for template expressions, and fail with an error that names the file, line and limit. Add a stack guard on the entry point, as #428 did for the other Rust entry points.
Pointers
crates/citry_i18n/src/compiler.rs(linking and validating patterns)fluent-syntax = "=0.12.0"in the rootCargo.toml- Prior art for depth limits:
crates/python_safe_eval/src/nesting.rs(MAX_NESTING),crates/python_safe_eval/src/stack.rs, fix: start each deep Rust entry point with a stack guard #428 - The weekly measurements in Run the internal depth and speed measurements weekly #528 could track both numbers.
Error mode
Today: a slow compile (part 1) or a crashed process (part 2) at startup or when citry i18n compiles a package. After the change: compiling fails with a clear error naming the file, message and limit. Add a test just under and just over each limit.
Activity