[v4] Decompression bomb: transformer-sharp no cap on source pixels
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- node.js, typescript
Research direction
Start by reading packages/transformer-sharp's transformFile.ts, handleRequest.ts, and prepareLegacyUpload.ts, which the issue identifies as the relevant entry points. Trace how options reach each Sharp constructor and how tryProbe obtains source dimensions; then check the package's tests for transformer and dynamic resize behavior. Done means oversized sources are rejected before pixel decoding with a clear 400, under a configurable budget across the paths described.
Written by the indexing model from the issue text.
Description
Describe the Bug
transformer-sharp: no cap on source pixels, a 2 KB AVIF can exhaust server memory
Summary
@payloadcms/transformer-sharp opens every uploaded image with Sharp's default input limit (268 megapixels) and offers no way to lower it for variants, crops or dynamic resizing. A highly compressible image (a flat-colour AVIF is the cheapest) is a few kilobytes on disk and several gigabytes once decoded, so upload.limits.fileSize does not help. Any account allowed to upload to a collection with a variant can push the server process past its memory limit with one request.
Versions
payloadand@payloadcms/transformer-sharp: 4.0.0-beta.8sharp: 0.35.5 (prebuilt libvips)- Node 24, macOS arm64
Measurements
I measured the Sharp calls the transformer makes, in isolation (same Sharp build, one fresh Node process per call, process.resourceUsage().maxRSS), not through a running Payload instance:
| Source | File size | sharp(buf).resize({ width: 600 }) |
sharp(buf).webp() |
|---|---|---|---|
| 7000 x 7000 (49 MP) | 1,525 bytes | 1.1 GB peak RSS | 1.3 GB |
| 12000 x 12000 (144 MP) | 2,079 bytes | 3.1 GB | 3.4 GB |
| 16000 x 16000 (256 MP) | 3,691 bytes | 5.2 GB, then throws | 5.2 GB, then throws |
sharp(buf).metadata()on the same files: 69 MB, 5 ms. Reading the header is safe.sharp(buf, { limitInputPixels: 50_000_000 })on the 256 MP file: throwsInput image exceeds pixel limitin 2 ms at 69 MB.- The 256 MP case ends with libheif's own error (
Security limit exceeded: Memory usage of 2304003546 bytes ... exceeds the security limit of 2147483648 bytes), but only after the process has reached 5.2 GB.
Where it happens
In packages/transformer-sharp (read from the published dist of beta.8):
transformFile.ts,transformSizeandtransformCrop: the constructor options are hard-coded to{ animated: true }or{}. Nothing a project configures reaches them.transformFile.ts,transformMain:constructorOptionsis spread into the constructor, solimitInputPixelscan be set there, but only for the main file, and only when the collection has adjustments.handleRequest.ts(dynamic resize):maxWidth,maxHeightandmaxPixelsbound the output. The source is still decoded in full bysharp(sourceBuffer, sharpOptions).rotate().resize(...).prepareLegacyUpload.ts:tryProbealready reads the source dimensions, and core'sprobeImageSizereads them from the header without decoding. Neither value is used to refuse an upload.
AVIF, GIF and WebP are also opened with animated: true, so a many-frame file multiplies the cost.
Expected behaviour
An upload whose decoded size exceeds a configurable budget is refused with a 400 before any pixel is decoded.
Suggested fix
- Add a
maxInputPixelsoption tosharpTransformer(global, overridable per collection) with a conservative default, well under Sharp's 268 MP. - Pass it as
limitInputPixelsto every Sharp constructor in the package: main file, crop, variants, probes and the dynamic handler. - Refuse early from the dimensions the probe already returns (times the frame count for animated sources), so the error is a clean 400 rather than a Sharp exception.
- Apply
constructorOptionsto variants and crops as well, or document that it only covers the main file. - In the dynamic handler, check the source pixel count from
metadata()before resizing.
Workaround
A beforeOperation hook that reads sharp(file.data).metadata() and rejects when width * height * (pages ?? 1) is above a budget, since it runs before the transformer.
Link to the code that reproduces this issue
pnpx create-payload-app@latest -t blank
Reproduction Steps
Generate the file:
import sharp from 'sharp';
await sharp({ create: { width: 12000, height: 12000, channels: 3, background: '#336699' } })
.avif({ effort: 0, quality: 30 })
.toFile('bomb.avif'); // 2,079 bytes
Upload it to a collection configured like this:
upload: {
limits: { fileSize: 5_000_000 },
transformers: [
sharpTransformer({ sharp, collections: { media: { variants: [{ name: 'thumbnail', width: 600 }] } } }),
],
}
Which area(s) are affected?
area: core
Environment Info
- `payload` and `@payloadcms/transformer-sharp`: 4.0.0-beta.8
- `sharp`: 0.35.5 (prebuilt libvips)
- Node 24, macOS arm64
- Dominant language
- TypeScript
- Stars
- 45.8k
- Forks
- 4.4k
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 251
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from payloadcms/payload
-
db-d1-sqlite: upsert is aliased to updateOne, so payload.kv.set never inserts new keysPossibly taken @pcbeingused333 claimed this today. OpenBug db: d1-sqlite Payload OSS
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
payloadcms/payload#19766 ·
Maintainers usually reply within 1 day
-
Document bar (.doc-controls__content) overflows a 375 px viewport, clips "Created" and fails axe scrollable-region-focusablePossibly taken A pull request linked to this issue is open or already merged. Openarea: ui Bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
payloadcms/payload#19690 ·
Maintainers usually reply within 1 day
-
[v4] Blocks thumbnails croped 3:2Possibly taken @samiarif02 claimed this 2 days ago. Openarea: ui Bug Payload OSS status: needs-triage v3
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
payloadcms/payload#19609 ·
Maintainers usually reply within 1 day
-
Scheduled publish jobs are not deleted when their document is deleted (string id in the job, raw id in the cleanup)Possibly taken @volodymyrshk claimed this 10 days ago. Openarea: core Bug db: sqlite
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
payloadcms/payload#19448 ·
Maintainers usually reply within 1 day
-
plugin-multi-tenant: `isGlobal` collections redirect tenant-scoped users to `/admin` since 3.93.0 (GlobalViewRedirect prop-name mismatch)Possibly taken @JarrodMFlesch claimed this 10 days ago. OpenBug plugin: multi-tenant
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
payloadcms/payload#19420 · 1 assignee ·
Maintainers usually reply within 1 day
All issues in payloadcms/payload
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
milind-soni/OpenMausBot#6730 ·
Maintainers usually reply within 1 day
-
`@angular/[email protected]` depends on vulnerable Vite 7.3.7 - GHSA-p4f5-76q4-ffq7 (Critical RCE)Openarea: @angular/build
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
angular/angular-cli#34764 ·
Maintainers usually reply within 1 day
-
status/need-triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
google-gemini/gemini-cli#30384 · 1 comment ·
Maintainers usually reply within 1 day
-
P2
Difficulty 1/5 Under an hour Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
area:image documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day