Repository navigation
fix(upload): honor sharp limitInputPixels config in image manipulation - #27161
Merged
Adzouz merged 3 commits intoOct 14, 2026
Merged
Conversation
Contributor
|
This PR has been added to our community triage board as CPR-465. |
giu1io
reviewed
Sep 16, 2026
giu1io
left a comment
Contributor
There was a problem hiding this comment.
Thank you for this PR! Overall great job, I've added suggestions for a couple of small fixes. 🙏
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
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Adzouz
force-pushed
the
fix/upload-sharp-limit-input-pixels
branch
from
October 14, 2026 19:07
affa16d to
16168ae
Compare
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
approved these changes
Oct 14, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does it do?
Threads the
plugin::upload.sharp.limitInputPixelsconfig value into every sharp instance the upload plugin's image-manipulation service creates (getMetadata, resizeFileTo, optimize, isFaultyImage; both file-path and stream inputs), and addslimitInputPixels?: number | booleanto the plugin'sConfig['sharp']type. When unconfigured, the service falls back to a baresharp()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
sharpconfig block, but only the globalcache/concurrencysettings were ever applied; a configuredlimitInputPixelswas silently ignored. Large images, notably animated GIFs whose stacked frames blow past sharp's default 268-megapixel limit underanimated: 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 viafalse, raised, and unset, on both file-path and stream inputs, across thumbnails, optimization, responsive formats, dimensions and the faulty-image check. Nine tests inconfig.test.tscover 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 atenv.int().Documentation
New row for the
#### Sharp configurationtable indocusaurus/docs/cms/features/media-library.md:limitInputPixelsfalseor0removes the limit.268402689(~268 megapixels)Caution
limitInputPixels: falseremoves 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 bareenv()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
limitInputPixelsto an invalid value (a string fromenv(), a negative, a fraction) will now fail to start until the value is fixed.Related issue(s)/PR(s)
Fixes #27159
Fixes CPR-465