[PR #2376] [MERGED] Cap per-entry decompressed size on .charx and .marinara import #5565

Closed
opened 2026-10-22 04:17:24 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2376
Author: @Romuromylus
Created: 6/5/2026
Status: ✅ Merged
Merged: 6/6/2026
Merged by: @Romuromylus

Base: refactor ← Head: fix/zip-decompression-bomb-cap


📝 Commits (1)

  • 1c61469 Cap per-entry decompressed size on .charx and .marinara import

📊 Changes

2 files changed (+84 additions, -18 deletions)

View changed files

📝 src-tauri/src/commands/storage/imports/marinara.rs (+2 -12)
📝 src-tauri/src/commands/storage/imports/payloads.rs (+82 -6)

📄 Description

Linked issue

Closes #2303

Why this change

read_zip_entry called read_to_end with no size bound, so a malicious .charx or .marinara archive with a high-compression-ratio entry could exhaust memory during decompression (zip bomb). marinara.rs only checked the size after the full read, which is too late.

What changed

  • Replace read_zip_entry with read_zip_entry_with_limit: it rejects on the declared uncompressed size before allocating, then streams via take(limit + 1) so the cap holds even if the ZIP header understates the entry — mirroring the existing copy_limited_profile_zip_asset_with_limit hardening in profile/assets.rs.
  • Thread per-entry caps through every call site (charx card.json 5 MiB, charx assets 50 MiB, marinara data.json 5 MiB, marinara avatar 20 MiB); remove the now-redundant post-read checks.

Refactor impact

Primary owner: Rust imports (src-tauri/src/commands/storage/imports/)

Impact areas reviewed:

  • payloads.rs (charx) and marinara.rs (.marinara) call sites.

Boundary notes:

  • none

Pressure points touched:

  • import modules (payloads.rs, marinara.rs)

Validation

  • Matching validation command passes locally
  • Full pnpm check passes before PR push/handoff
  • Human/manual validation completed by contributor or reviewer

Manual verification notes

  • cargo clippy --workspace --all-targets -- -D warnings — clean
  • cargo test --workspace — green, including 4 new read_zip_entry* tests (oversized rejected, within-limit accepted, uncapped read, missing entry).

Feature Discoverability

  • N/A because this PR is a security bugfix and does not add a new thing users need to find.

Reason:

  • Hardening of an existing import path.

Docs and release impact

  • No docs changes needed

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/2376 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 6/5/2026 **Status:** ✅ Merged **Merged:** 6/6/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `refactor` ← **Head:** `fix/zip-decompression-bomb-cap` --- ### 📝 Commits (1) - [`1c61469`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1c61469cd66c2b80e4d46610e5035dc1923cef2c) Cap per-entry decompressed size on .charx and .marinara import ### 📊 Changes **2 files changed** (+84 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/src/commands/storage/imports/marinara.rs` (+2 -12) 📝 `src-tauri/src/commands/storage/imports/payloads.rs` (+82 -6) </details> ### 📄 Description ## Linked issue Closes #2303 ## Why this change `read_zip_entry` called `read_to_end` with no size bound, so a malicious `.charx` or `.marinara` archive with a high-compression-ratio entry could exhaust memory during decompression (zip bomb). `marinara.rs` only checked the size *after* the full read, which is too late. ## What changed - Replace `read_zip_entry` with `read_zip_entry_with_limit`: it rejects on the declared uncompressed size before allocating, then streams via `take(limit + 1)` so the cap holds even if the ZIP header understates the entry — mirroring the existing `copy_limited_profile_zip_asset_with_limit` hardening in `profile/assets.rs`. - Thread per-entry caps through every call site (charx `card.json` 5 MiB, charx assets 50 MiB, marinara `data.json` 5 MiB, marinara avatar 20 MiB); remove the now-redundant post-read checks. ## Refactor impact Primary owner: Rust imports (`src-tauri/src/commands/storage/imports/`) Impact areas reviewed: - `payloads.rs` (charx) and `marinara.rs` (.marinara) call sites. Boundary notes: - none Pressure points touched: - import modules (`payloads.rs`, `marinara.rs`) ## Validation - [ ] Matching validation command passes locally - [ ] Full `pnpm check` passes before PR push/handoff - [ ] Human/manual validation completed by contributor or reviewer ### Manual verification notes - `cargo clippy --workspace --all-targets -- -D warnings` — clean - `cargo test --workspace` — green, including 4 new `read_zip_entry*` tests (oversized rejected, within-limit accepted, uncapped read, missing entry). ## Feature Discoverability - [x] N/A because this PR is a security bugfix and does not add a new thing users need to find. Reason: - Hardening of an existing import path. ## Docs and release impact - [x] No docs changes needed --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:17:24 +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#5565
No description provided.