[GH-ISSUE #2523] [Issue]: .charx import/inspect decompresses with no size or entry-count cap (zip-bomb OOM) #1250

Closed
opened 2026-10-21 05:29:57 +07:00 by bsakaguchi · 0 comments
Owner

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

Originally assigned to: @Romuromylus on GitHub.

Summary

Severity: High — security / crash (uncapped decompression DoS). The .charx character-card import and inspect paths decompress zip entries into memory with no uncompressed-size or entry-count cap, so a small, highly compressible upload can expand to multiple GB and OOM-kill the shared server for every user. The sibling /marinara-package import already caps both.

Expected behavior

.charx import should bound decompression cost before paying it: cap the entry count and check each entry's uncompressed size (from the zip central directory) before calling getData(), exactly as /marinara-package does.

Actual behavior

importCharX/inspectCharX build an AdmZip and call getData() on entries with no bounds. card.json is read via JSON.parse(cardEntry.getData()...) and assets via entry.getData() with no size guard:

// packages/server/src/services/import/st-character.importer.ts
export async function importCharX(buf: Buffer, db: DB, options?: STCharacterImportOptions) {
  const zip = new AdmZip(buf);
  // ... no entry-count / header.size check anywhere before getData()
}
function readCharXCardJson(zip: AdmZip): Record<string, unknown> | null {
  const cardEntry = zip.getEntry("card.json");
  if (!cardEntry) return null;
  return JSON.parse(cardEntry.getData().toString("utf-8")) as Record<string, unknown>;
}

The 256 MB multipart fileSize cap (app.ts:44, app.ts:66-68) limits only the compressed upload. DEFLATE reaches ~1000:1 on repetitive data, so a few-MB .charx expands to multiple GB in a single getData() Buffer, exhausting the Node heap. The path is reachable post-basicAuth with no privileged gate via POST /st-character, POST /st-character/inspect, and POST /st-character/batch (packages/server/src/routes/import.routes.ts:654/695/722).

Steps to reproduce

  1. Craft a .charx (a zip) whose card.json or an embedded asset is a few MB compressed but decompresses to multiple GB (a long run of repeated bytes compresses extremely well).
  2. As any authenticated user, upload it to POST /st-character (or POST /st-character/inspect).
  3. The server allocates the full decompressed buffer in memory and OOM-crashes, taking down the shared instance for all users.

Environment

  • Marinara Engine version: 1.6.1 (staging @ a9fdae8)
  • Install type: source
  • OS + version: n/a — static source audit
  • Browser or app shell: n/a

Logs, screenshots, or video

Static source audit, cited to file:line above.

Additional context

Fix: mirror the in-repo reference at import.routes.ts:599-627 (/marinara-package), which caps zip.getEntries().length (MAX_PACKAGE_ENTRIES = 8) and checks each entry.header.size (uncompressed size from the central directory) before any getData(). The bounded-decompress pattern is also modeled in utils/security.ts:506-523 (maxOutputLength on gunzip/brotli/zstd) and backup.routes.ts:1424 (inflateRawSync(..., { maxOutputLength })). Add the same entry-count + per-entry header.size gate inside importCharX/inspectCharX, covering all unguarded getData() sites: readCharXCardJson (:339), the asset fallback loop (:299), and resolveCharXAsset (~:473).

Regression notes: found via static audit. This code is byte-identical on main (65a0395) — importCharX/inspectCharX/readCharXCardJson are unbounded on both branches — so it is a long-standing shared-engine bug, not a main→staging regression. The /marinara-package cap also predates the fork, so this is a fix-pattern-already-in-repo inconsistency rather than a fork-introduced gap.

Template check

Please uncheck (untick) 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 9, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2523 Originally assigned to: @Romuromylus on GitHub. ## Summary **Severity: High — security / crash (uncapped decompression DoS).** The `.charx` character-card import and inspect paths decompress zip entries into memory with no uncompressed-size or entry-count cap, so a small, highly compressible upload can expand to multiple GB and OOM-kill the shared server for every user. The sibling `/marinara-package` import already caps both. ## Expected behavior `.charx` import should bound decompression cost before paying it: cap the entry count and check each entry's uncompressed size (from the zip central directory) before calling `getData()`, exactly as `/marinara-package` does. ## Actual behavior `importCharX`/`inspectCharX` build an `AdmZip` and call `getData()` on entries with no bounds. `card.json` is read via `JSON.parse(cardEntry.getData()...)` and assets via `entry.getData()` with no size guard: ```ts // packages/server/src/services/import/st-character.importer.ts export async function importCharX(buf: Buffer, db: DB, options?: STCharacterImportOptions) { const zip = new AdmZip(buf); // ... no entry-count / header.size check anywhere before getData() } function readCharXCardJson(zip: AdmZip): Record<string, unknown> | null { const cardEntry = zip.getEntry("card.json"); if (!cardEntry) return null; return JSON.parse(cardEntry.getData().toString("utf-8")) as Record<string, unknown>; } ``` The 256 MB multipart `fileSize` cap (`app.ts:44`, `app.ts:66-68`) limits only the *compressed* upload. DEFLATE reaches ~1000:1 on repetitive data, so a few-MB `.charx` expands to multiple GB in a single `getData()` Buffer, exhausting the Node heap. The path is reachable post-basicAuth with no privileged gate via `POST /st-character`, `POST /st-character/inspect`, and `POST /st-character/batch` (`packages/server/src/routes/import.routes.ts:654/695/722`). ## Steps to reproduce 1. Craft a `.charx` (a zip) whose `card.json` or an embedded asset is a few MB compressed but decompresses to multiple GB (a long run of repeated bytes compresses extremely well). 2. As any authenticated user, upload it to `POST /st-character` (or `POST /st-character/inspect`). 3. The server allocates the full decompressed buffer in memory and OOM-crashes, taking down the shared instance for all users. ## Environment - Marinara Engine version: 1.6.1 (`staging @ a9fdae8`) - Install type: source - OS + version: n/a — static source audit - Browser or app shell: n/a ## Logs, screenshots, or video Static source audit, cited to file:line above. ## Additional context Fix: mirror the in-repo reference at `import.routes.ts:599-627` (`/marinara-package`), which caps `zip.getEntries().length` (`MAX_PACKAGE_ENTRIES = 8`) and checks each `entry.header.size` (uncompressed size from the central directory) before any `getData()`. The bounded-decompress pattern is also modeled in `utils/security.ts:506-523` (`maxOutputLength` on gunzip/brotli/zstd) and `backup.routes.ts:1424` (`inflateRawSync(..., { maxOutputLength })`). Add the same entry-count + per-entry `header.size` gate inside `importCharX`/`inspectCharX`, covering all unguarded `getData()` sites: `readCharXCardJson` (~`:339`), the asset fallback loop (~`:299`), and `resolveCharXAsset` (~`:473`). Regression notes: found via static audit. This code is byte-identical on `main` (`65a0395`) — `importCharX`/`inspectCharX`/`readCharXCardJson` are unbounded on both branches — so it is a long-standing shared-engine bug, not a `main`→`staging` regression. The `/marinara-package` cap also predates the fork, so this is a fix-pattern-already-in-repo inconsistency rather than a fork-introduced gap. ## Template check Please **uncheck (untick)** 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:29:57 +07:00
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#1250
No description provided.