mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #2532] [MERGED] fix(import): cap .charx entry count and decompressed size to prevent zip-bomb OOM #5638
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#5638
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2532
Author: @Romuromylus
Created: 6/9/2026
Status: ✅ Merged
Merged: 6/9/2026
Merged by: @SpicyMarinara
Base:
staging← Head:fix/charx-zip-bomb-cap📝 Commits (2)
54dd4b7fix(import): cap .charx entry count and decompressed size to prevent zip-bomb OOM62a3b19Merge branch 'staging' into fix/charx-zip-bomb-cap📊 Changes
1 file changed (+37 additions, -0 deletions)
View changed files
📝
packages/server/src/services/import/st-character.importer.ts(+37 -0)📄 Description
Linked issue
Closes #2523
Why this change
.charximport (RisuAI Character Card V3 zip) decompressed entries with no bound on entry count or uncompressed size. adm-zip'sgetData()allocates the full uncompressed entry as a single Buffer, and the 256 MB multipart cap inapp.tsbounds only the compressed upload. DEFLATE reaches ~1000:1 on repetitive data, so a few-MB.charxcan expand to multiple GB and OOM the shared server process — a denial-of-service against every user on the instance.What changed
assertCharXWithinLimits(zip)inst-character.importer.ts. It reads each entry's central-directoryheader.size(the uncompressed size, available without decompressing) and the entry count, rejecting before anygetData()materializes a buffer:.charxlegitimately carriescard.jsonplus many asset images),new AdmZip(buf)in bothimportCharXandinspectCharX. Because it validates up front, it transitively guards all three downstreamgetData()sites (readCharXCardJson, the asset fallback loop,resolveCharXAsset) without touching them.{ success: false, error }— no server crash, no new logging.This mirrors the existing
/marinara-packagebounds inimport.routes.ts(MAX_PACKAGE_ENTRIES+ theheader.sizecheck beforegetData()).Not a regression: the
.charxpaths are byte-identical onmain; this is a long-standing shared-code hardening.Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
pnpm checkpasses locally. I also added a local-only node:test (charx-bomb.test.ts, gitignored per repo convention) covering: a legitimate small.charxaccepted (positive control), exactly 512 entries accepted (boundary, not off-by-one), and rejection of too-many-entries (513), an oversize entry (>64 MB uncompressed), and total-budget overflow (>256 MB). Local run: 5/5 pass.Still to verify manually in a real browser against the deploy:
.charxand confirm the character appears (happy path unaffected)..charxwith 600+ trivial entries and confirm the UI shows a graceful import error and the server stays up (no restart).Docs and release impact
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.