# RUSTSEC-2026-0311: Stack overflow on deeply nested LaTeX input

> Attackers can crash applications using the latex-rust library by submitting deeply nested LaTeX input, causing a stack overflow and process abort.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 27 Sep 2026

## What is RUSTSEC-2026-0311?

RUSTSEC-2026-0311 is a denial of service vulnerability in latex-rust, published on 27 Sep 2026. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

The parser and layout engine in affected versions of `latex-rust` recurse once
per level of nesting with no limit. Deeply nested input, such as `\frac{1}{…}`,
braces, `\sqrt{…}`, `\left(`, or superscripts nested hundreds or thousands of
levels deep, exhausts the call stack.

A stack overflow in Rust aborts the process. It is not a panic, so it cannot be
caught with `catch_unwind`. A program that renders LaTeX from untrusted input
can therefore be terminated by a short string. With a release build on an 8 MiB
stack, 700 nested `\frac{1}{…}` (about 7 KB of input) abort version 1.0.4, and
10,000 nested braces (about 20 KB) abort it as well. The threshold is lower on
smaller stacks and in debug builds; on a 2 MiB thread in a debug build, about
35 nested fractions are enough.

```rust
let mut src = String::from("1");
for _ in 0..700 {
    src = format!("\\frac{{1}}{{{src}}}");
}
let _ = latex_rust::parse(&src); // stack overflow, process aborts
```

The fixed versions count nesting depth in the parser and in `layout` and
refuse input that nests more than 32 levels. `parse`, `parse_with_colors`, and
the `latex_to_*` functions return
`ParseError::Malformed("input nests deeper than 32 levels")`, and `layout`
returns `Error::Unsupported { what: "tree nests deeper than 32 levels" }` for a
tree built by hand. The count is of parser recursion levels, and a braced
argument costs two, so the limit admits 15 nested `\frac`, `\sqrt`, or
`x^{…}`, and 31 nested groups, `\left…\right` pairs, or environments. Input
past the limit is refused within about 100 KiB of stack in an optimised build.

Version 1.0.5 fixes this with no API changes and is a drop-in replacement for
1.0.4; upgrade with `cargo update -p latex-rust`. It also includes the 2.0.0
rendering fixes, so rendered output differs from 1.0.4. Versions 2.0.0 and
2.0.1 contain the same fix, with the same limit and messages, together with
breaking API changes relative to 1.x, and also let callers change the limit
with `ParseOptions` and `layout_with_max_depth`.

## Which versions are affected by RUSTSEC-2026-0311?

1 open source package ship an affected version, including latex-rust.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `latex-rust` | crates.io | From 0.0.0-0 | 1.0.5 |

## How do I fix RUSTSEC-2026-0311?

Upgrade latex-rust to 1.0.5 or later.

## Is RUSTSEC-2026-0311 being exploited?

There is no known exploitation of RUSTSEC-2026-0311 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for RUSTSEC-2026-0311 and fix it if it is affected.

What it is: RUSTSEC-2026-0311 is a denial of service vulnerability in latex-rust, published on 27 Sep 2026. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of RUSTSEC-2026-0311 in the wild and no public exploit code.

Affected packages and fixed versions:
- latex-rust (crates.io): affected from 0.0.0-0; fixed in 1.0.5

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/RUSTSEC-2026-0311/ (Markdown: https://insights.sbomify.com/RUSTSEC-2026-0311/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/RUSTSEC-2026-0311

---
From sbomify Insights: https://insights.sbomify.com/RUSTSEC-2026-0311/
Summaries are generated and may contain mistakes; the official description above is the record.
