[GH-ISSUE #2303] [Issue]: Decompression bomb in .charx / .marinara import — read_zip_entry has no decompressed-size cap #1138

Closed
opened 2026-10-21 05:27:40 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @Romuromylus on GitHub (Jun 5, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2303

Originally assigned to: @Romuromylus on GitHub.

Summary

Severity: Medium — Security (decompression bomb / DoS). The shared zip-entry helper read_zip_entry calls read_to_end() with no cap on the decompressed size. A small crafted .charx or .marinara file (a few KB/MB) can declare a DEFLATE entry that inflates to many GB, exhausting memory and crashing the process. The sibling profile-zip extractor is properly hardened; these import paths are not.

Expected behavior

Zip entry reads should enforce a per-entry decompressed-size cap during decompression (e.g. reader.take(limit + 1) then reject if the limit is hit), and pre-check entry.size() against the cap before reading — mirroring the profile-zip path. A total-extracted-bytes budget across the entries of an archive is also warranted.

Actual behavior

read_zip_entry (src-tauri/src/commands/storage/imports/payloads.rs:87-103) fully materializes the decompressed entry with no bound:

let result = match zip_reader.by_name(name) {
    Ok(mut file) => {
        let mut contents = Vec::new();
        file.read_to_end(&mut contents)?;   // no size cap on the DECOMPRESSED stream

Two reachable entry points share this helper:

  • .charx — extract_charx (payloads.rs:178) and resolve_charx_asset (142, fallback loop 214) call read_zip_entry, then base64-encode the result (adds ~1.33×). Reached via parse_character_file -> extract_charx from the /import/st-character, /import/st-character/batch, /import/st-character/inspect routes, and from the folder/batch import path (bulk_imports.rs:1287-1289 does fs::read(&path) with no size limit).
  • .marinara — import_marinara_file (imports/marinara.rs:41-49 for data.json, 67-74 for the avatar) checks data_bytes.len() / avatar.len() against MAX_DATA_JSON_BYTES (5 MB) / MAX_AVATAR_BYTES (20 MB) only after read_zip_entry has already decompressed the whole entry into a Vec<u8>:
let data_bytes = read_zip_entry(&uploaded.bytes, &data_entry)?
    .ok_or_else(|| AppError::invalid_input(".marinara file is missing data.json"))?;
if data_bytes.len() > MAX_DATA_JSON_BYTES {   // checked only AFTER read_to_end already decompressed everything

MAX_PACKAGE_ENTRIES = 8 bounds entry count, not per-entry decompressed size. In server mode the request body is capped at MAX_API_BODY_BYTES = 256 MB, but DEFLATE's ~1000:1 ratio means a sub-256 MB compressed body inflates to hundreds of GB, so the body cap does not protect either path.

Steps to reproduce

  1. Build a .charx (or .marinara) whose card.json / data.json / avatar entry is a DEFLATE bomb (small compressed, multi-GB decompressed).
  2. Import it (desktop: open the file / folder import; server: POST the route).
  3. Observe memory blowing up to OOM and the process crashing.

Impact area

  • Catalog resources
  • Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime

Environment

  • Branch or commit: refactor @ 47b16701
  • Run mode: Tauri desktop (DoS-on-self) and opt-in server mode (remote DoS)
  • OS + version: not relevant (static source audit)
  • Node + pnpm versions: not relevant
  • Rust version, if relevant: not relevant
  • Remote Runtime URL configured? applies to both
  • Provider, model, or integration, if relevant: n/a

Logs, screenshots, or video

Static source audit; claims cited to file:line above. Do not attach a real bomb file.

Regression notes

Found via static audit of the refactor branch; not verified against main. The fix pattern already exists in-repo: commands/storage/profile/assets.rs defines MAX_PROFILE_ASSET_BYTES (256 MB, line 22), validate_profile_zip_asset_declared_size checks entry.size() (466/496/568), and copy_limited_profile_zip_asset_with_limit streams via reader.take(limit + 1) (588). The charx/marinara paths do neither.

Additional context

Impact is a crash / OOM DoS (no RCE, no data loss, recoverable on restart). Desktop is largely self-inflicted (single-user importing an attacker-supplied file); the bigger risk is server mode, where a single 256 MB request can OOM-kill the shared process and per-IP rate limiting does not help. Suggested fix: make read_zip_entry size-bounded (take an explicit per-entry limit, stream with take(limit + 1), reject on overflow), pre-check file.size() against the relevant cap before reading, and apply a total-extracted-bytes budget across the entries iterated in extract_charx.

Template check

Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Romuromylus on GitHub (Jun 5, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2303 Originally assigned to: @Romuromylus on GitHub. ## Summary **Severity: Medium — Security (decompression bomb / DoS).** The shared zip-entry helper `read_zip_entry` calls `read_to_end()` with no cap on the **decompressed** size. A small crafted `.charx` or `.marinara` file (a few KB/MB) can declare a DEFLATE entry that inflates to many GB, exhausting memory and crashing the process. The sibling profile-zip extractor is properly hardened; these import paths are not. ## Expected behavior Zip entry reads should enforce a per-entry decompressed-size cap **during** decompression (e.g. `reader.take(limit + 1)` then reject if the limit is hit), and pre-check `entry.size()` against the cap before reading — mirroring the profile-zip path. A total-extracted-bytes budget across the entries of an archive is also warranted. ## Actual behavior `read_zip_entry` (`src-tauri/src/commands/storage/imports/payloads.rs:87-103`) fully materializes the decompressed entry with no bound: ```rust let result = match zip_reader.by_name(name) { Ok(mut file) => { let mut contents = Vec::new(); file.read_to_end(&mut contents)?; // no size cap on the DECOMPRESSED stream ``` Two reachable entry points share this helper: - **`.charx`** — `extract_charx` (`payloads.rs:178`) and `resolve_charx_asset` (`142`, fallback loop `214`) call `read_zip_entry`, then base64-encode the result (adds ~1.33×). Reached via `parse_character_file -> extract_charx` from the `/import/st-character`, `/import/st-character/batch`, `/import/st-character/inspect` routes, and from the folder/batch import path (`bulk_imports.rs:1287-1289` does `fs::read(&path)` with no size limit). - **`.marinara`** — `import_marinara_file` (`imports/marinara.rs:41-49` for `data.json`, `67-74` for the avatar) checks `data_bytes.len()` / `avatar.len()` against `MAX_DATA_JSON_BYTES` (5 MB) / `MAX_AVATAR_BYTES` (20 MB) only **after** `read_zip_entry` has already decompressed the whole entry into a `Vec<u8>`: ```rust let data_bytes = read_zip_entry(&uploaded.bytes, &data_entry)? .ok_or_else(|| AppError::invalid_input(".marinara file is missing data.json"))?; if data_bytes.len() > MAX_DATA_JSON_BYTES { // checked only AFTER read_to_end already decompressed everything ``` `MAX_PACKAGE_ENTRIES = 8` bounds entry *count*, not per-entry decompressed *size*. In server mode the request body is capped at `MAX_API_BODY_BYTES = 256 MB`, but DEFLATE's ~1000:1 ratio means a sub-256 MB compressed body inflates to hundreds of GB, so the body cap does not protect either path. ## Steps to reproduce 1. Build a `.charx` (or `.marinara`) whose `card.json` / `data.json` / avatar entry is a DEFLATE bomb (small compressed, multi-GB decompressed). 2. Import it (desktop: open the file / folder import; server: POST the route). 3. Observe memory blowing up to OOM and the process crashing. ## Impact area - [x] Catalog resources - [x] Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime ## Environment - Branch or commit: refactor @ 47b16701 - Run mode: Tauri desktop (DoS-on-self) and opt-in server mode (remote DoS) - OS + version: not relevant (static source audit) - Node + pnpm versions: not relevant - Rust version, if relevant: not relevant - Remote Runtime URL configured? applies to both - Provider, model, or integration, if relevant: n/a ## Logs, screenshots, or video Static source audit; claims cited to file:line above. Do not attach a real bomb file. ## Regression notes Found via static audit of the refactor branch; not verified against main. The fix pattern already exists in-repo: `commands/storage/profile/assets.rs` defines `MAX_PROFILE_ASSET_BYTES` (256 MB, line 22), `validate_profile_zip_asset_declared_size` checks `entry.size()` (466/496/568), and `copy_limited_profile_zip_asset_with_limit` streams via `reader.take(limit + 1)` (588). The charx/marinara paths do neither. ## Additional context Impact is a crash / OOM DoS (no RCE, no data loss, recoverable on restart). Desktop is largely self-inflicted (single-user importing an attacker-supplied file); the bigger risk is server mode, where a single 256 MB request can OOM-kill the shared process and per-IP rate limiting does not help. Suggested fix: make `read_zip_entry` size-bounded (take an explicit per-entry limit, stream with `take(limit + 1)`, reject on overflow), pre-check `file.size()` against the relevant cap before reading, and apply a total-extracted-bytes budget across the entries iterated in `extract_charx`. ## Template check Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:27:40 +07:00
Author
Owner

@Romuromylus commented on GitHub (Jun 6, 2026):

Fixed by #2376, merged into refactor (squash 09268c5d).

<!-- gh-comment-id:4637084689 --> @Romuromylus commented on GitHub (Jun 6, 2026): Fixed by #2376, merged into `refactor` (squash 09268c5d).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#1138
No description provided.