mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #1640] [MERGED] Preflight upload sizes before reading whole files into memory #5173
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#5173
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/1640
Author: @Romuromylus
Created: 5/30/2026
Status: ✅ Merged
Merged: 5/30/2026
Merged by: @Romuromylus
Base:
refactor← Head:fix/upload-size-preflight📝 Commits (2)
afbf2c6Preflight upload sizes before reading whole files into memory85c8e8aFormat file-payload test to repository Prettier style📊 Changes
6 files changed (+100 additions, -15 deletions)
View changed files
📝
src/engine/contracts/constants/defaults.ts(+1 -0)📝
src/features/modes/game/components/GameInput.tsx(+3 -1)📝
src/shared/api/assets-api.ts(+6 -2)📝
src/shared/api/file-payload.test.ts(+58 -1)📝
src/shared/api/file-payload.ts(+11 -3)📝
src/shared/api/import-api.ts(+21 -8)📄 Description
Why this change
fileToUploadPayloadalready short-circuits oversized files beforefile.arrayBuffer()when given amaxBytes, but several callers invoked it (orFileReader) with no limit, so the entire file was read and base64-encoded before any size check ran:formDataToJsonis the funnel for every import-api file path but passed no limit, so chat imports read the whole file first.uploadGameAssetread the whole asset before sending; the API layer never enforced a limit (only one of its two callers, the Settings panel, had an inline UI check).GameInput.handleFileUploadcarried an inline20 * 1024 * 1024magic number beforeFileReader.readAsDataURL.What changed
file-payload.ts:formDataToJsongains an optionalFilePayloadOptions(maxBytes/tooLargeMessage) and threads it tofileToUploadPayload, so a File entry is rejected before its bytes are read. ExportedFilePayloadOptions+ two message constants.import-api.ts:filePayload/filesPayloadaccept and forward the options; the chat import paths (stChat,stChatIntoGroup) pass theCHAT_JSONL(50 MB) limit.assets-api.ts:uploadGameAssetpreflights against a newMAX_FILE_SIZES.GAME_ASSET(50 MB), matching the existing Settings upload gate and staying under the 75 MB RustMAX_MEDIA_ASSET_BYTESserver ceiling.GameInput.tsx: replace the inline 20 MB magic number withMAX_FILE_SIZES.IMAGE_UPLOAD(same value, now named).Verification
pnpm exec tsc -bclean.file-payload.test.tscases proveformDataToJsonrejects an oversized File beforearrayBufferis called, encodes a within-limit file while preserving string fields, and stays backward-compatible with no limit.src/shared/apisuite (92 tests) green.The end-user upload triggers (game-asset upload, ST chat import) run through the native file picker, which the automated tiers don't drive; the size-preflight behavior they depend on is covered by the unit tests against
formDataToJson/fileToUploadPayload.Follow-ups (deferred, not blocking this PR)
The two remaining named import paths are intentionally left uncapped here because choosing a safe whole-file limit needs a maintainer decision, and a wrong value would reject valid imports:
stCharacterFile/stCharacterBatch/stCharacterInspectaccept PNG character cards as well as JSON. The declaredCHARACTER_JSONlimit (5 MB) is too small for PNG cards, and the Rustimport_st_characterpath enforces no whole-file cap, so applying 5 MB would reject valid cards.marinaraFileuploads a.marinaraZIP. The Rust side capsdata.jsonat 5 MB and the avatar at 20 MB per entry after unzip; the whole-package size has no server cap, so a tight whole-file limit would reject valid packages.The mechanism to cap them (
formDataToJsonmaxBytes) is now in place, so the follow-up is a one-line change per caller once the intended limits are chosen.Linked issue
Closes #1538.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.