mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #1636] [MERGED] Validate uploaded image bytes instead of trusting declared MIME type #5167
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#5167
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/1636
Author: @Romuromylus
Created: 5/30/2026
Status: ✅ Merged
Merged: 5/30/2026
Merged by: @Romuromylus
Base:
refactor← Head:fix/validate-image-upload-bytes📝 Commits (3)
ea67161Validate uploaded image bytes instead of trusting declared MIME typee40d14fFix image-byte validation test fixture and accept SVG uploads003aae5Require📊 Changes
2 files changed (+167 additions, -1 deletions)
View changed files
📝
src-tauri/src/commands/storage/shared.rs(+164 -0)📝
src-tauri/src/http_dispatch.rs(+3 -1)📄 Description
Why this change
decode_uploaded_image_file(shared upload decoder) already rejects empty payloads, oversized payloads, and non-image declared content types, but it still trusted a declaredimage/*MIME type without validating the decoded bytes. A caller could declareimage/pngand send arbitrary non-image bytes, which passed the decoder and were stored / later served as an image.What changed
src-tauri/src/commands/storage/shared.rs: after decoding (and after the existing size checks), validate the decoded bytes. For raster types,image::guess_formatrejects bytes that match no recognized image signature (accepting every real raster format, including ones whose decoder feature is not compiled in, e.g. GIF). SVG is an accepted upload type (image/svg+xml, inIMAGE_EXTS, reachable viaaccept="image/*") but is XML text with no binary magic, so it is special-cased to require a recognizable<svgroot instead, which still rejects non-SVG bytes declared as SVG.src-tauri/src/http_dispatch.rs: the shared upload test fixture emitted only the 4-byte PNG prefix; emit the full 8-byte PNG signature so it is recognized as a real image.image/pngwith non-image bytes is rejected; a real 1x1 PNG is accepted; a real SVG is accepted; svg-typed non-SVG bytes are rejected.Verification
cargo clippy --workspace --all-targets -- -D warningsclean.dispatch_supports_remote_*_uploadtests (fixture fixed) and thedecode_uploaded_image_*suite (6 tests).The end-user trigger (uploading through an image/background path) reaches this decoder via the native file picker, which the automated tiers don't drive; the decoder's byte-level behavior is fully covered by the tests.
Linked issue
Closes #1534.
Summary by CodeRabbit
Bug Fixes
Tests
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.