EPUB spine repetition causes unbounded output/CPU/memory amplification in the read path (11 KB file -> minutes of CPU or OOM)
Description
Confirmed against a clean checkout of main (commit 01d60817761b2a0a78ec7117532f3d12aa3a5472). An 11 KB crafted EPUB causes unbounded output/CPU/memory amplification in the read path: the EPUB spine loop renders one section per <itemref> with no deduplication and no cumulative-output cap, so repeating a single chapter N times multiplies the work N-fold. This defeats the resource-bounding property docs/guide/security.md explicitly claims.
Details
crates/anymd-formats/src/epub.rs:15-17:MAX_ENTRIES,MAX_TOTAL_UNCOMPRESSED,MAX_ENTRY_BYTESbound the zip's distinct entries and declared sizes — not how many times one entry is re-rendered.crates/anymd-formats/src/epub.rs:58-76: the spine loop pushes one(path, xhtml)per<itemref>with no dedup bypath. The same chapter referenced 400 times produces 400 reads/renders.crates/anymd-formats/src/epub.rs:85-112: onerender_html+Sectionpush per spine entry, no cumulative-output cap.- The
readtool'sDEFAULT_MAX_TOKENS = 20_000cap (crates/anymd/src/lean.rs:24) is applied inbudget_fromafterconvert(...)has already materialized every section's full markdown. The budget truncates the printed text, not the work.
docs/guide/security.md:47 states as a guarantee: "resource limits bound page count, rendered pixels, and output size." No such cumulative bound exists for EPUB spine repetition. (The doc's phrasing is PDF-centric, which a maintainer could dispute as not covering EPUB.)
Proof of concept (local only, clean upstream main @ 01d6081)
Built the real anymd binary (the backend the MCP read tool calls) in an isolated rust:latest container; ran reads in debian:stable-slim, --network none, 6 GB memory cgroup. Crafted EPUB: one ~10 MB XHTML chapter referenced 400× in <spine>; 11 KB on disk.
CONTROL benign 1-chapter EPUB (1 MB), no flags -> prints full text, exits 0 immediately
ATTACK evil.epub, --max-tokens 20000 (MCP default) -> ~1m54s wall, output correctly truncated to ~100 KB
ATTACK evil.epub, no cap (CLI default) -> OOM-killed (exit 137) after ~2m41s under 6 GB cap, 0 bytes producedLibrary-level amplification (direct anymd_formats::convert): N=400, 10 MB chapter, 11 KB input -> 4.19 GB rendered markdown (~379,000x) in 15.8 s.
Impact
Availability only. A user or agent opening an attacker-supplied EPUB (the common MCP case), or an authenticated/loopback HTTP caller supplying one, ties up the server for minutes or OOM-kills it from an 11 KB file. No confidentiality/integrity effect.
Suggested fix
Deduplicate spine entries by resolved path (or cap repeated renders of the same entry), and enforce a cumulative-output cap in convert before materializing all sections, consistent with the docs/guide/security.md "output size" guarantee.
Severity
stdio / agent-opens-file: CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H (~5.5)
HTTP transport, API-key/loopback: CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H (~6.5)My estimates, deferring to your judgment. Resource-exhaustion / zip-bomb-style amplification (CWE-400/CWE-409).
AI disclosure
Produced with AI assistance: an automated scan followed by independent verification. The amplification was reproduced end-to-end through the real compiled anymd binary on a clean upstream checkout, with a benign-file control that completes immediately. Each claim was re-read against current source before inclusion.
Credit
GitHub: @zohuyhieuzo03 (finder).
Resolution
Fixed in v8.5.10 (7c670ea4b992d924dfc049626d943b066a825299, f048a4704afe5b5bf085886c09811c71f8309a72) by deduplicating EPUB <spine> <itemref> entries by canonical in-archive path and enforcing a cumulative conversion output byte cap (MAX_CONVERTED_MARKDOWN_BYTES) before materializing sections.