Skip to content

fix(upload): honor sharp limitInputPixels config in image manipulation - #27161

Merged
Adzouz merged 3 commits into
strapi:developfrom
Mohith26:fix/upload-sharp-limit-input-pixels
Oct 14, 2026
Merged

Adzouz merged 3 commits into
strapi:developfrom
Mohith26:fix/upload-sharp-limit-input-pixels

Conversation

@Mohith26

@Mohith26 Mohith26 commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

What does it do?

Threads the plugin::upload.sharp.limitInputPixels config value into every sharp instance the upload plugin's image-manipulation service creates (getMetadata, resizeFileTo, optimize, isFaultyImage; both file-path and stream inputs), and adds limitInputPixels?: number | boolean to the plugin's Config['sharp'] type. When unconfigured, the service falls back to a bare sharp() call (an empty options object breaks sharp's stream-input detection), so default behavior is unchanged.

Why is it needed?

Fixes #27159, reported by @GrayYoung. The upload plugin advertises a sharp config block, but only the global cache/concurrency settings were ever applied; a configured limitInputPixels was silently ignored. Large images, notably animated GIFs whose stacked frames blow past sharp's default 268-megapixel limit under animated: true, always failed with "Input image exceeds pixel limit" regardless of configuration.

How to test it?

Seventeen tests in image-manipulation-sharp-options.test.ts (real sharp, existing fixtures) cover the limit enforced when lowered, disabled via false, raised, and unset, on both file-path and stream inputs, across thumbnails, optimization, responsive formats, dimensions and the faulty-image check. Nine tests in config.test.ts cover the startup validation of the value. Full upload server suite: 674 passed.

To try it in an app, set sharp: { limitInputPixels: 1000 } in the upload plugin config: uploaded images are then rejected. Set it to the string '1000' instead and Strapi refuses to start, with an error pointing at env.int().

Documentation

New row for the #### Sharp configuration table in docusaurus/docs/cms/features/media-library.md:

Option Description Default
limitInputPixels Largest image sharp accepts, as a pixel count (width × height × frames for animated images), not a size in bytes. false or 0 removes the limit. sharp's default, 268402689 (~268 megapixels)

Caution

limitInputPixels: false removes sharp's protection against decompression bombs: small crafted files that decode into gigabytes of pixels. Anyone with upload permission can reach it. Prefer raising the limit to a number over disabling it.

When reading the value from the environment, use env.int('SHARP_LIMIT_INPUT_PIXELS'). A bare env() returns a string, which Strapi now rejects at startup with a clear error.

Upgrade note: before this PR the option was ignored entirely. An app that already sets limitInputPixels to an invalid value (a string from env(), a negative, a fraction) will now fail to start until the value is fixed.

Related issue(s)/PR(s)

Fixes #27159


Fixes CPR-465

@strapi-cla

strapi-cla commented Jul 29, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@dosubot dosubot Bot added pr: fix This PR is fixing a bug source: core:upload Source is core/upload package labels Jul 29, 2026
@github-actions github-actions Bot added the community Changes and fixes created by community members label Jul 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been added to our community triage board as CPR-465.

@giu1io giu1io left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this PR! Overall great job, I've added suggestions for a couple of small fixes. 🙏

Mohith26 and others added 3 commits October 14, 2026 15:03
The upload plugin config accepts a sharp option block, but only the
global settings (cache, concurrency) were applied at register time.
The per-instance limitInputPixels option was silently ignored because
none of the sharp pipelines in the image manipulation service received
instance options, so uploads of large images (e.g. animated GIFs whose
stacked frames exceed sharp's default 268MP limit) always failed with
"Input image exceeds pixel limit" regardless of configuration.

Thread the configured limitInputPixels value into every sharp instance
created by the image manipulation service (metadata, resize, optimize
and faulty-image checks, for both file-path and stream inputs).

Fix #27159
@Adzouz
Adzouz force-pushed the fix/upload-sharp-limit-input-pixels branch from affa16d to 16168ae Compare October 14, 2026 19:07
@Adzouz Adzouz added the qa-skipped Only applied when QA needs to be skipped label Oct 14, 2026
@Adzouz

Adzouz commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Hi @Mohith26, I took the liberty to take over the PR to move forward and merge it, I hope you don't mind 🙏

@Adzouz Adzouz self-assigned this Oct 14, 2026
@Adzouz Adzouz added this to the 5.58.1 milestone Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Changes and fixes created by community members pr: fix This PR is fixing a bug qa-skipped Only applied when QA needs to be skipped source: core:upload Source is core/upload package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sharp limitInputPixels does not work for upload

4 participants