fix(files): bound the HEIF fallback decode input - #6348
Conversation
Uploads allow 100MB and prepareImageForVision runs sharp with limitInputPixels: false, so nothing upstream capped what could reach the single-threaded WebAssembly decoder. A tenant-controlled file could therefore spend unbounded CPU and memory on one read. Cap the transcode input at 20MB — generous headroom over any phone photo, which runs 1-4MB. Pixel-dimension bombs stay bounded by libheif's own security limits during parse.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryLow Risk Overview Oversized buffers are rejected before the dynamic import/decode, logged with a warning, and return A unit test asserts buffers above Reviewed by Cursor Bugbot for commit bc6d949. Configure here. |
Greptile SummaryThe PR prevents oversized HEIF files from reaching the WebAssembly fallback decoder.
Confidence Score: 5/5The PR appears safe to merge with no actionable defects identified. The input guard executes before decoder loading, and the sole caller already converts a null result into the intended unavailable-image response.
|
| Filename | Overview |
|---|---|
| apps/sim/lib/uploads/server/heic.ts | Adds an early 20 MiB guard that safely follows the helper's existing nullable contract and avoids invoking the decoder. |
| apps/sim/lib/uploads/server/heic.test.ts | Verifies that input one byte above the ceiling is rejected with null. |
Reviews (1): Last reviewed commit: "fix(files): bound the HEIF fallback deco..." | Re-trigger Greptile
Summary
Follow-up to #6346, which merged before this commit landed on the branch — the HEIF decoder went out without an input bound.
Nothing upstream capped what could reach the WebAssembly decoder: uploads allow 100MB (
validation.ts:15) andprepareImageForVisionruns sharp withlimitInputPixels: false. A tenant-controlled file could therefore spend unbounded CPU and memory on a single-threaded decode during one copilot read.transcodeHeicToJpegnow refuses input above a 20MB ceiling and returnsnull, which the existing "[Image unavailable]" path already handles. 20MB leaves generous headroom over any phone photo — a 12MP iPhone HEIC runs 1-4MB.Scope — what this does and does not cover
Security limit exceededbefore any decode happens.Raised by Greptile on #6346 and worth disagreeing with if 20MB or the pixel-vector reasoning looks wrong.
Type of Change
Testing
Added a test asserting input above the ceiling returns
nullwithout invoking the decoder. 19 tests, typecheck clean.Checklist