Skip to content

Cap PNG dimensions to avoid memory exhaustion (OCU-01-016) - #216

Open
AayushKumar26 wants to merge 1 commit into
OpenPrinting:masterfrom
AayushKumar26:fix/ocu-01-016-png-memory-cap
Open

Cap PNG dimensions to avoid memory exhaustion (OCU-01-016)#216
AayushKumar26 wants to merge 1 commit into
OpenPrinting:masterfrom
AayushKumar26:fix/ocu-01-016-png-memory-cap

Conversation

@AayushKumar26

Copy link
Copy Markdown
Contributor

What this fixes

Fixes #215 (audit finding OCU-01-016).

_cfImageReadPNG() loads interlaced PNGs all at once, allocating xsize * ysize * 3 in a single malloc. 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

  • Added 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 malloc NULL check, so real PNGs keep printing and only unreasonable input is rejected.

_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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OCU-01-016 WP3: Memory Exhaustion via Interlaced PNG (Medium)

1 participant