mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2616] [Issue]: PNG character-card parser reads chunk length as signed int32 — crafted card freezes the browser tab #1289
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#1289
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 @Romuromylus on GitHub (Jun 18, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2616
Originally assigned to: @Romuromylus on GitHub.
Summary
Severity: Medium — crash / DoS. The client PNG character-card parser reads the 4-byte chunk length with signed 32-bit bitwise ops. A crafted card whose chunk-length field has the high bit set decodes to a negative length, sending the chunk-walk cursor far negative and pinning the JS main thread for ~13-16 seconds (empirically reproduced), freezing the tab while importing the card.
Expected behavior
Parsing a malformed/crafted PNG card should fail fast (reject the file), not block the main thread.
Actual behavior
A chunk length of
0x80000000decodes to a negative number. From then on, out-of-bounds reads returnundefined(coerced to0by<<), solengthstays0, the type never matchesIEND, andoffsetonly advances+12per iteration insidewhile (offset < bytes.length). Empirically: a 100-byte buffer whose first chunk length is0x80000000startedoffsetat ~-2.1 billion and ran 66M+ iterations in 5s, still at offset -1.35B — a guaranteed multi-second full main-thread freeze.parsePngCharacterCardruns on remote/attacker-controlled bytes from the bot-browser import paths (BotBrowserView.tsx:1542,BotBrowserModal.tsx:200), matching the malicious-imported-content threat model. (Not literally infinite —offseteventually climbs back pastbytes.lengthand exits — but the freeze is severe.)Steps to reproduce
0x80000000); no valid character data is needed.Environment
staging @ 56f700cd(v2.0.0)Logs, screenshots, or video
Static source audit, cited to file:line above. Empirically reproduced in Node (66M+ loop iterations on a crafted 100-byte buffer).
Additional context
Fix sketch. Read the length unsigned (
>>> 0, orDataView.getUint32(offset, false)) and add loop guards: bail iflength < 0, iflengthis absurdly large, or ifoffset + 8 + lengthoverrunsbytes.length; and break ifoffsetdoes not strictly increase. The in-repo reference isread-zip-text.ts:9-15, whosereadUint32already reads unsigned via>>> 0—png-parser.tsdoes not.Regression notes. Not a regression —
png-parser.tsis byte-identical onmain(same signed read, sameoffset += length + 4). Shared pre-existing bug on both branches.Template check
@Romuromylus commented on GitHub (Jun 18, 2026):
Fixed in #2623, merged to
staging(e1132e5b). Closing manually since the PR targetedstagingrather than the default branch.