[PR #4292] [MERGED] Bound NovelAI ZIP decompression output #6321

Closed
opened 2026-10-23 04:09:19 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/4292
Author: @SpicyMarinara
Created: 7/30/2026
Status: ✅ Merged
Merged: 7/30/2026
Merged by: @SpicyMarinara

Base: staging ← Head: security/bound-novelai-zip-output


📝 Commits (2)

  • 9a860e8 security: bound NovelAI ZIP decompression
  • 31cf4b0 use DataView for ZIP size parsing

📊 Changes

4 files changed (+154 additions, -13 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 package.json (+2 -1)
📝 packages/server/src/services/image/image-generation.ts (+28 -12)
➕ scripts/regressions/novelai-zip-security.regression.ts (+123 -0)

📄 Description

Linked issue

Closes #4286

Why this change

Provider responses are untrusted input. NovelAI ZIP extraction needs a strict decompressed-output budget so a corrupted or adversarial archive cannot consume unbounded memory through misleading metadata or a high expansion ratio.

What changed

  • Enforce a 64 MiB decompressed-output ceiling.
  • Parse ZIP sizes as unsigned little-endian values and reject oversized declarations before inflation.
  • Pass the same ceiling to the inflater and validate actual output against the declared size.
  • Validate stored-entry sizes and reject malformed or unsupported archive structures.
  • Add focused regressions for valid stored/deflated responses, oversized declarations, expansion overflow, size mismatches, and malformed archives.
  • Document the hardening in the changelog.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Automated proof completed before publication:

  • pnpm regression:novelai-zip-security
  • pnpm check
  • pnpm version:check
  • git diff --check staging...security/bound-novelai-zip-output

Manual verification notes

  • Manually generate an image with a live NovelAI account and verify a normal ZIP response still renders.
  • Manually confirm a rejected archive produces a useful provider error.
  • No live NovelAI generation was performed in this agent run.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

CHANGELOG.md is updated; no user guide under docs/ changes in this lane.

UI evidence (if applicable)

Not applicable; this changes server-side provider response parsing.

Summary by CodeRabbit

  • Security

    • Improved handling of NovelAI ZIP image responses by rejecting malformed, oversized, truncated, or unexpectedly expanding data.
    • Added safeguards to ensure extracted image data matches the sizes declared in the archive.
  • Bug Fixes

    • Prevented unsafe decompression of highly expanding or invalid ZIP responses.
  • Tests

    • Added regression coverage for valid ZIP images and malicious or malformed archive conditions.

🔄 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/4292 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 7/30/2026 **Status:** ✅ Merged **Merged:** 7/30/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `security/bound-novelai-zip-output` --- ### 📝 Commits (2) - [`9a860e8`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9a860e8b5269a783250a058bbadf783b28767556) security: bound NovelAI ZIP decompression - [`31cf4b0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/31cf4b037fb4c01a1bcda3278832c50e003f82e0) use DataView for ZIP size parsing ### 📊 Changes **4 files changed** (+154 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `package.json` (+2 -1) 📝 `packages/server/src/services/image/image-generation.ts` (+28 -12) ➕ `scripts/regressions/novelai-zip-security.regression.ts` (+123 -0) </details> ### 📄 Description ## Linked issue Closes #4286 ## Why this change Provider responses are untrusted input. NovelAI ZIP extraction needs a strict decompressed-output budget so a corrupted or adversarial archive cannot consume unbounded memory through misleading metadata or a high expansion ratio. ## What changed - Enforce a 64 MiB decompressed-output ceiling. - Parse ZIP sizes as unsigned little-endian values and reject oversized declarations before inflation. - Pass the same ceiling to the inflater and validate actual output against the declared size. - Validate stored-entry sizes and reject malformed or unsupported archive structures. - Add focused regressions for valid stored/deflated responses, oversized declarations, expansion overflow, size mismatches, and malformed archives. - Document the hardening in the changelog. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` Automated proof completed before publication: - `pnpm regression:novelai-zip-security` - `pnpm check` - `pnpm version:check` - `git diff --check staging...security/bound-novelai-zip-output` ### Manual verification notes - Manually generate an image with a live NovelAI account and verify a normal ZIP response still renders. - Manually confirm a rejected archive produces a useful provider error. - No live NovelAI generation was performed in this agent run. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) `CHANGELOG.md` is updated; no user guide under `docs/` changes in this lane. ## UI evidence (if applicable) Not applicable; this changes server-side provider response parsing. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Security** * Improved handling of NovelAI ZIP image responses by rejecting malformed, oversized, truncated, or unexpectedly expanding data. * Added safeguards to ensure extracted image data matches the sizes declared in the archive. * **Bug Fixes** * Prevented unsafe decompression of highly expanding or invalid ZIP responses. * **Tests** * Added regression coverage for valid ZIP images and malicious or malformed archive conditions. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:09:19 +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#6321
No description provided.