Repository navigation
Limit how much a PNG's iCCP profile can inflate in readIccProfile - #1572
Merged
hipstersmoothie merged 1 commit intoNov 27, 2026
Merged
Conversation
hipstersmoothie
approved these changes
Nov 27, 2026
Collaborator
|
🚀 PR was released in |
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's Changing and Why
readIccProfileinflates a PNG'siCCPchunk withunzlibSyncand puts no limit on the output, so a chunk of zeros inflates to about a thousand times the size of the file it came from (CWE-409).@jimp/pngjsalready caps compressed metadata at 16 MB (MAX_METADATA_LENGTH, foriCCP,zTXtandiTXt), but a chunk over that limit only makesparseAncillarythrow, andreadPngskips broken metadata so the image still decodes.readMetadatathen hands the same bytes to core's own PNG parser, which has no limit.Jimp.fromBufferon a 1x1 PNG with an oversizediCCPchunk, Node 24, median of 5 runs, memory being the growth inarrayBuffers:The profile in those runs is all zeros, so
profileColorSpacerejects it andiccProfileends up undefined. All of that work is wasted.@jimp/serverreads up to 20 MB per request by default, which is about 20 GB of profile.The chunk now goes through fflate's streaming
Unzlib16 KB at a time and stops at the same 16 MB, so the cost stops growing with what the stream inflates to. What's left in the "after" column is the 16 MB both limits allow, inflated twice: once by@jimp/pngjsand once here.What else might be affected
A PNG carrying an ICC profile over 16 MB loses it.
@jimp/pngjsalready refuses to read one that large, and the biggest profile in the test fixtures is 71 KB.Streaming matches
unzlibSyncon broken data: a truncated or garbage stream throws the same way, andreadIccProfilecatches that and returns undefined, as before. Valid profiles inflate to the same bytes.Tasks
jimp.d.tsThe test builds a PNG whose profile is padded to the limit and one padded a byte past it: the first keeps its profile, the second doesn't. It fails on
main, where the oversized profile is read in full.pnpm build,pnpm lint,pnpm testandpnpm test:browserpass locally, apart from the codec conformance packages that need the Git LFS corpus, which fail the same way without this change.