RUSTSEC-2026-0311
Vulnerability from osv_rustsec – Published: 2026-09-27 12:00 – Updated: 2026-09-28 08:34 – Source websiteThe 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.
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": [
{
"database_specific": {
"categories": [
"denial-of-service"
],
"cvss": null,
"informational": null
},
"ecosystem_specific": {
"affected_functions": null,
"affects": {
"arch": [],
"functions": [
"latex_rust::latex_to_png",
"latex_rust::latex_to_shapes",
"latex_rust::latex_to_svg",
"latex_rust::layout",
"latex_rust::layout_with_numbering",
"latex_rust::parse",
"latex_rust::parse_with_colors"
],
"os": []
}
},
"package": {
"ecosystem": "crates.io",
"name": "latex-rust",
"purl": "pkg:cargo/latex-rust"
},
"ranges": [
{
"events": [
{
"introduced": "0.0.0-0"
},
{
"fixed": "1.0.5"
}
],
"type": "SEMVER"
}
],
"versions": []
}
],
"aliases": [],
"database_specific": {
"license": "CC0-1.0"
},
"details": "The parser and layout engine in affected versions of `latex-rust` recurse once\nper level of nesting with no limit. Deeply nested input, such as `\\frac{1}{\u2026}`,\nbraces, `\\sqrt{\u2026}`, `\\left(`, or superscripts nested hundreds or thousands of\nlevels deep, exhausts the call stack.\n\nA stack overflow in Rust aborts the process. It is not a panic, so it cannot be\ncaught with `catch_unwind`. A program that renders LaTeX from untrusted input\ncan therefore be terminated by a short string. With a release build on an 8 MiB\nstack, 700 nested `\\frac{1}{\u2026}` (about 7 KB of input) abort version 1.0.4, and\n10,000 nested braces (about 20 KB) abort it as well. The threshold is lower on\nsmaller stacks and in debug builds; on a 2 MiB thread in a debug build, about\n35 nested fractions are enough.\n\n```rust\nlet mut src = String::from(\"1\");\nfor _ in 0..700 {\n src = format!(\"\\\\frac{{1}}{{{src}}}\");\n}\nlet _ = latex_rust::parse(\u0026src); // stack overflow, process aborts\n```\n\nThe fixed versions count nesting depth in the parser and in `layout` and\nrefuse input that nests more than 32 levels. `parse`, `parse_with_colors`, and\nthe `latex_to_*` functions return\n`ParseError::Malformed(\"input nests deeper than 32 levels\")`, and `layout`\nreturns `Error::Unsupported { what: \"tree nests deeper than 32 levels\" }` for a\ntree built by hand. The count is of parser recursion levels, and a braced\nargument costs two, so the limit admits 15 nested `\\frac`, `\\sqrt`, or\n`x^{\u2026}`, and 31 nested groups, `\\left\u2026\\right` pairs, or environments. Input\npast the limit is refused within about 100 KiB of stack in an optimised build.\n\nVersion 1.0.5 fixes this with no API changes and is a drop-in replacement for\n1.0.4; upgrade with `cargo update -p latex-rust`. It also includes the 2.0.0\nrendering fixes, so rendered output differs from 1.0.4. Versions 2.0.0 and\n2.0.1 contain the same fix, with the same limit and messages, together with\nbreaking API changes relative to 1.x, and also let callers change the limit\nwith `ParseOptions` and `layout_with_max_depth`.",
"id": "RUSTSEC-2026-0311",
"modified": "2026-09-28T08:34:35Z",
"published": "2026-09-27T12:00:00Z",
"references": [
{
"type": "PACKAGE",
"url": "https://crates.io/crates/latex-rust"
},
{
"type": "ADVISORY",
"url": "https://rustsec.org/advisories/RUSTSEC-2026-0311.html"
},
{
"type": "REPORT",
"url": "https://github.com/jscarr64/LaTeX-Rust/issues/6"
},
{
"type": "WEB",
"url": "https://github.com/jscarr64/LaTeX-Rust/pull/10"
},
{
"type": "WEB",
"url": "https://github.com/jscarr64/LaTeX-Rust/releases/tag/v1.0.5"
}
],
"related": [],
"severity": [],
"summary": "Stack overflow on deeply nested LaTeX input"
}
Sightings
| Author | Source | Type | Date | Other |
|---|
Nomenclature
- Seen: The vulnerability was mentioned, discussed, or observed by the user.
- Confirmed: The vulnerability has been validated from an analyst's perspective.
- Published Proof of Concept: A public proof of concept is available for this vulnerability.
- Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
- Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
- Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
- Not confirmed: The user expressed doubt about the validity of the vulnerability.
- Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.
The approach is described in our paper Mapping CVEs to MITRE ATT&CK Techniques: A Curated Gold-Set Classifier and the Limits of LLM-Assisted Label Expansion.
Browse all ATT&CK techniques and the vulnerabilities related to each.
Related by attack behaviour
Vulnerabilities whose description is nearest to this one in the vector space of the CIRCL/vulnerability-attack-technique-biencoder model. This is a similarity search over the bi-encoder space (plain cosine), not a classification, and it has no measured accuracy.