Cap PNG dimensions to avoid memory exhaustion (OCU-01-016) - #216
Open
AayushKumar26 wants to merge 1 commit into
Open
Cap PNG dimensions to avoid memory exhaustion (OCU-01-016)#216AayushKumar26 wants to merge 1 commit into
AayushKumar26 wants to merge 1 commit into
Conversation
_cfImageReadPNG() loads interlaced PNGs all at once, allocating xsize*ysize*3 in one malloc. The existing checks only catch overflow of that product, not large-but-valid sizes, so a crafted interlaced PNG could request an enormous allocation from a small file. Cap each dimension at 283465 px (5 m at 1440 dpi), which keeps the size multiplication from overflowing; allocations still too large for the machine then fail gracefully at the existing malloc NULL check. Fixes OpenPrinting#215
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 this fixes
Fixes #215 (audit finding OCU-01-016).
_cfImageReadPNG()loads interlaced PNGs all at once, allocatingxsize * ysize * 3in a singlemalloc. The existing checks only catch integer overflow of that multiplication, not large-but-valid sizes, so a crafted interlaced PNG with huge dimensions can request an enormous allocation from a small compressed file and exhaust memory in the filter child. It's reachable through the normal PNG print path.The changes
CF_IMAGE_MAX_PIXELS(283465), the pixels-per-side for a 5m print at 1440 dpi, which covers the largest realistic print (5m-wide inkjets exist)._cfImageReadPNG()now rejects images whose width or height exceeds that.Bounding each dimension keeps the decoded-size multiplication from overflowing. Any allocation still too large for the machine then fails gracefully at the existing
mallocNULL check, so real PNGs keep printing and only unreasonable input is rejected.