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

> Archived entry. Full-text search covers entries since 2026-11-10; exact IDs work for all years.

- **Severity:** UNSCORED
- **Exploited in the wild:** Not in CISA KEV
- **Public exploit / PoC:** None known
- **Remote exploitation:** Unknown
- **Published:** 2026-09-27T12:00:00.000Z
- **Modified:** 2026-09-28T08:45:03.080Z

## Who should check

- Projects that depend on crates.io package latex-rust (\>= 0.0.0-0, \< 1.0.5)

## 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\`.

## Affected and fixed versions

- crates.io `latex-rust`: affected \>= 0.0.0-0, \< 1.0.5; fixed 1.0.5 (osv)

## Mitigation

- Upgrade latex-rust to 1.0.5 or later.

## Check your systems with an agent

Paste this into a coding agent:

```text
Check whether anything I run is affected by RUSTSEC-2026-0311. Work read-only: do not install, upgrade, delete or change anything.

Details: https://flawdb.com/RUSTSEC-2026-0311.md
Affected: latex-rust >= 0.0.0-0, < 1.0.5
Fixed in: 1.0.5

Steps:
1. Search this machine and project for latex-rust (crates.io): dependency manifests and lockfiles, installed packages, container images and running services.
2. For each match, note the installed version and whether it is inside the affected range.
3. Report a table: location, installed version, affected (yes / no / unsure), evidence. If affected, say which fixed version or mitigation from the details link applies, but don't apply it.
```

## FAQ

### Is RUSTSEC-2026-0311 being exploited?

There is no confirmed exploitation: RUSTSEC-2026-0311 is not in the CISA Known Exploited Vulnerabilities catalog. No public exploit code is known.

### How serious is RUSTSEC-2026-0311?

It has no CVSS score yet. Unknown.

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

latex-rust \>= 0.0.0-0, \< 1.0.5.

### Is there a fix for RUSTSEC-2026-0311?

Yes. Fixed in 1.0.5. Upgrade latex-rust to 1.0.5 or later.

### How do I check if I'm affected by RUSTSEC-2026-0311?

Find where you use the affected software (dependency lockfiles, installed packages, container images, servers) and compare the installed version with the affected range above. The agent prompt on this page does this read-only.

## References

- vendor: <https://rustsec.org/advisories/RUSTSEC-2026-0311.html>
- patch: <https://github.com/jscarr64/LaTeX-Rust/pull/10>
- other: <https://crates.io/crates/latex-rust>
- other: <https://github.com/jscarr64/LaTeX-Rust/issues/6>
- other: <https://github.com/jscarr64/LaTeX-Rust/releases/tag/v1.0.5>

## Attribution

- OSV: CC-BY 4.0 <https://osv.dev/vulnerability/RUSTSEC-2026-0311> (license: <https://creativecommons.org/licenses/by/4.0/>)

HTML: <https://flawdb.com/RUSTSEC-2026-0311> · JSON: <https://flawdb.com/api/v1/entries/RUSTSEC-2026-0311>
