Skip to content

Add depth limits to the i18n compiler and the Fluent parser #561

Open

Description

@JuroOravec

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

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

  1. added
    next-sprint
    on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    next-sprint

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions