mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #3062] [Issue]: RunPod image extraction accepts unvalidated base64/image fallback fields, saving an error string as a corrupt image #1630
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#1630
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?
Originally created by @kolacheee on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3062
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
In
extractRunPodImage, the primarydatafield is validated with a base64 character-class regex before being accepted, but thebase64/imagefallback fields are accepted with NO validation — no regex check and no decoded-byte-length check.detectImageMimeTypefalls back toimage/pngfor anything it can't sniff. So a COMPLETED RunPod response like{ output: { images: [{ base64: "<error/garbage>" }] } }(or animagekey holding a status/error string) is returned as a successful result and flows tosaveImageToDisk, which doesBuffer.from(garbage, "base64")and writes a corrupt file that is served to the user as their generated image. Thedata-path data-URL branch and the OpenAI/Stability decoders all reject empty/invalid base64; this fallback branch is the only extraction path with no validation.How to reproduce (try it yourself)
runpod_comfyuiconnection at an endpoint whose handler returns{ output: { images: [{ base64: "model not ready" }] } }(a non-base64 string in the fallback key, nodatafield).You'll see: the function returns
{ base64: "model not ready", mimeType: "image/png", ext: "png" }instead of throwing, and a corrupt file (decoded from a 9-byte garbage buffer) is saved and served rather than the provider error being surfaced.Expected: an invalid fallback value is skipped and the existing 'Could not extract image' error is surfaced.
Where it is
packages/server/src/services/image/runpod-comfyui.service.ts:img.base64/img.imagewith no regex and no decoded-length check, returning the string verbatim.databranch validates with/^[A-Za-z0-9+/]*={0,2}$/(line 234) and routes data URLs todecodeDataUrl(which rejects zero-length buffers, line 373).extractRunPodImagehas one caller, line 161 (the COMPLETED branch ofgenerateRunPodComfyUI). Result flows tosaveImageToDisk(image-generation.ts:222) with no intervening validation.What's happening
The fallback branch skips the base64 validation the primary
databranch applies and never verifies the decoded buffer is non-empty, so any string is treated as a valid image. Theimagesarray is typed as records ofunknown, so a COMPLETED job whosebase64key holds an error string reaches this defensive fallback and is written to disk.Suggested fix
Apply the same validation the
datafield uses to thebase64/imagefallback, andcontinueon failure so the loop tries the next image and ultimately hits the existing "Could not extract image" error. Replace the unvalidated block (lines 248-256) with:(The
data:branch is optional parity with thedatafield; omitting it just lets data URLs fail the regex and fall through. Either way the corrupt-file bug is fixed.)Regression avoided: the fix is contained in
extractRunPodImage(one caller, no shared helper with other providers). A genuine PNG/JPEG base64 still passes the regex andbyteLength > 0check; empty/whitespace strings (already skipped by theif (fallbackBase64)guard, now also by the byteLength check)continueto the existing error fall-through, so error shape is unchanged. Adata:URL accidentally placed in the fallback key is now rejected by the char-class regex rather than written as a corrupt raw-base64 file — strictly safer.AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.
@SpicyMarinara commented on GitHub (Jun 29, 2026):
Claiming this for the current staging sweep in draft PR #3064: https://github.com/Pasta-Devs/Marinara-Engine/pull/3064
@SpicyMarinara commented on GitHub (Jun 29, 2026):
Fixed in PR #3064 on branch
codex/issue-sweep-3054-3063(commit3ae8ca37). Closing this issue as addressed; the PR remains open for staging review/merge.