[codex] Harden desktop image data URL handling#3003
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
📝 WalkthroughWalkthroughCentralizes image MIME type and extension handling by introducing shared utility functions ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
1 issue found across 8 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/desktop/src/main/lib/project-icons.ts">
<violation number="1" location="apps/desktop/src/main/lib/project-icons.ts:116">
P2: Reject empty base64 payloads before saving; the new parser path allows `data:image/...;base64,` and writes a 0-byte icon file.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
|
|
||
| const ext = match[1] === "jpeg" ? "jpg" : match[1]; | ||
| const buffer = Buffer.from(match[2], "base64"); | ||
| const { buffer, ext } = parseProjectIconDataUrl(dataUrl); |
There was a problem hiding this comment.
P2: Reject empty base64 payloads before saving; the new parser path allows data:image/...;base64, and writes a 0-byte icon file.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/desktop/src/main/lib/project-icons.ts, line 116:
<comment>Reject empty base64 payloads before saving; the new parser path allows `data:image/...;base64,` and writes a 0-byte icon file.</comment>
<file context>
@@ -89,14 +113,7 @@ export async function saveProjectIconFromDataUrl({
-
- const ext = match[1] === "jpeg" ? "jpg" : match[1];
- const buffer = Buffer.from(match[2], "base64");
+ const { buffer, ext } = parseProjectIconDataUrl(dataUrl);
if (buffer.length > MAX_ICON_SIZE) {
</file context>
| const { buffer, ext } = parseProjectIconDataUrl(dataUrl); | |
| const { buffer, ext } = parseProjectIconDataUrl(dataUrl); | |
| if (buffer.length === 0) { | |
| throw new Error("Invalid data URL format"); | |
| } |
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
(cherry picked from commit 5839970)
Summary
.icouploads with surfaced mutation errorsWhy
Project icon uploads were relying on a narrow regex in the main-process save path. That broke valid browser-generated data URLs for formats like ICO variants and SVG data URLs with extra MIME parameters. The same MIME parsing pattern also existed in other desktop upload flows.
Impact
image/x-iconandimage/vnd.microsoft.iconValidation
bun test apps/desktop/src/shared/file-types.test.ts apps/desktop/src/main/lib/project-icons.test.tsbunx biome check --write 'apps/desktop/src/main/lib/project-icons.ts' 'apps/desktop/src/main/lib/project-icons.test.ts' 'apps/desktop/src/shared/file-types.ts' 'apps/desktop/src/shared/file-types.test.ts' 'apps/desktop/src/lib/trpc/routers/window.ts' 'apps/desktop/src/renderer/routes/_authenticated/settings/account/components/AccountSettings/AccountSettings.tsx' 'apps/desktop/src/renderer/routes/_authenticated/settings/organization/components/OrganizationSettings/OrganizationSettings.tsx' 'apps/desktop/src/renderer/routes/_authenticated/settings/project/$projectId/components/ProjectSettings/ProjectSettings.tsx'bunx tsc -p apps/desktop/tsconfig.json --noEmit --ignoreDeprecations 6.0currently fails on an existing unrelated error inapps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx(62,4): error TS2871: This expression is always nullish.Summary by cubic
Centralized and hardened desktop image data URL parsing/normalization to fix project icon uploads and make desktop image uploads consistent. Icons now accept ICO variants and SVG data URLs with extra parameters, and errors surface in the UI.
Bug Fixes
image/x-iconandimage/vnd.microsoft.icon; JPEG normalized to.jpg; SVG with extra params parsed correctly..icoandimage/vnd.microsoft.icon; show toast on mutation errors.Refactors
shared/file-typeshelpers:getImageMimeType,getImageExtensionFromMimeType,parseBase64DataUrl; reused across project, account, and org uploads.parseProjectIconDataUrlwith a PNG/JPEG/SVG/ICO allowlist.shared/file-typesand project icon parsing.Written for commit 83baf82. Summary will update on new commits.
Summary by CodeRabbit
New Features
Bug Fixes