Skip to content

Guard against oversized PICT canvas allocation - #15

Open
grub-basket wants to merge 1 commit into
jorio:masterfrom
grub-basket:harden/pict-canvas-alloc
Open

Guard against oversized PICT canvas allocation#15
grub-basket wants to merge 1 commit into
jorio:masterfrom
grub-basket:harden/pict-canvas-alloc

Conversation

@grub-basket

Copy link
Copy Markdown

Problem

convert_pict_to_image() reads the canvas rectangle as four signed 16-bit ints straight from the file, then immediately allocates a 4-byte-per-pixel white canvas from width * height with no bounds check:

canvas_rect = PICTRect(*u.unpack(">4h"))
canvas_32bit = b"\xFF\xFF\xFF\xFF" * (canvas_rect.width * canvas_rect.height)

A malformed PICT declaring a maximal canvas (top=-32768, left=-32768, bottom=32767, right=32767 → 65535×65535) forces a ~17 GB allocation from only a few input bytes. Since PICT is a standard converter, this fires automatically while extracting an untrusted resource fork — a memory-exhaustion DoS.

Fix

Reject negative or implausibly large canvas dimensions with PICTError before allocating (cap at ~64 megapixels — far beyond any legitimate classic QuickDraw picture). The JSON extractor already catches PICTError and falls back to a base16 dump, so a bad PICT degrades gracefully instead of taking down the process. The cap is a named constant, easy to tune.


Prepared with Claude Fable 5 (Low effort mode). Please review before merging.

convert_pict_to_image() read the canvas rectangle as four signed 16-bit
ints straight from the file and immediately allocated a 4-byte-per-pixel
white canvas from width*height, with no bounds check. A malformed PICT
declaring a ~65535x65535 canvas forces a multi-gigabyte allocation from
only a few input bytes (memory-exhaustion DoS when extracting an
untrusted resource fork, since PICT is a standard converter).

Reject negative or implausibly large canvas dimensions with PICTError
before allocating. The JSON extractor already catches PICTError and falls
back to a base16 dump, so a bad PICT degrades gracefully instead of
taking down the process.
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.

1 participant