Guard against oversized PICT canvas allocation - #15
Open
grub-basket wants to merge 1 commit into
Open
Conversation
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.
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.
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 fromwidth * heightwith no bounds check: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. SincePICTis 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
PICTErrorbefore allocating (cap at ~64 megapixels — far beyond any legitimate classic QuickDraw picture). The JSON extractor already catchesPICTErrorand 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.