T09 · Insecure Skill Coding Practices
- Location
scripts/handoff_common.py:48- Finding
Unbounded Image Dimensions Permit Resource Exhaustion
- Content
View full analysis
Vulnerability Details
File Location:
scripts/handoff_common.py:48-55
Vulnerability Type: Unrestricted resource allocation from user-controlled image dimensions
Risk Level: MediumVulnerable Code
python def parse_dimensions(value: str) -> tuple[int, int]: normalized = value.lower().replace(" ", "") parts = normalized.split("x", 1) if len(parts) != 2: raise ValueError(f"Invalid dimensions '{value}', expected WIDTHxHEIGHT") width, height = int(parts[0]), int(parts[1]) if width <= 0 or height <= 0: raise ValueError(f"Dimensions must be positive: {value}") return width, heightThe resulting dimensions are subsequently used in resource-intensive Pillow operations, including image resizing in
scripts/ingest_images.py:66-73and canvas/image processing inscripts/render_mixed_overlay.py:256-286.Technical Analysis
parse_dimensions()only verifies that the supplied width and height are positive integers. It does not impose limits on either dimension or on the total pixel count calculated aswidth * height.Dimensions originate from the user-controlled JSON specification or mixed-overlay plan. Values such as
1000000x1000000therefore pass validation. Downstream Pillow operations may then attempt to resize an image or allocate a canvas with one trillion pixels. Depending on image mode and intermediate buffers, this can require multiple terabytes of memory and substantial CPU or disk resources.Although Pillow may reject some extreme values or terminate with an allocation error, relying on library-specific failure behavior does not provide a reliable application-level resource boundary.
Attack Path
- An attacker or untrusted workflow input supplies a handoff specification or overlay plan containing an extremely large positive dimension, such as
1000000x1000000. parse_dimensions()accepts the value because both integers are positive.- The workflow reaches an image operati ...[truncated 1032 chars]
- An attacker or untrusted workflow input supplies a handoff specification or overlay plan containing an extremely large positive dimension, such as
- Remediation
View remediation
Remediation Suggestions
- Define explicit limits for each dimension and total pixel count. For example:
python MAX_IMAGE_WIDTH = 16384 MAX_IMAGE_HEIGHT = 16384 MAX_IMAGE_PIXELS = 100_000_000 def parse_dimensions(value: str) -> tuple[int, int]: normalized = value.lower().replace(" ", "") parts = normalized.split("x", 1) if len(parts) != 2: raise ValueError(f"Invalid dimensions '{value}', expected WIDTHxHEIGHT") width, height = int(parts[0]), int(parts[1]) if width <= 0 or height <= 0: raise ValueError(f"Dimensions must be positive: {value}") if width > MAX_IMAGE_WIDTH or height > MAX_IMAGE_HEIGHT: raise ValueError(f"Dimensions exceed supported limits: {value}") if width * height > MAX_IMAGE_PIXELS: raise ValueError(f"Image pixel count exceeds supported limit: {value}") return width, height-
Apply the same limits before every Pillow allocation or resize operation, rather than relying only on validation during initial handoff preparation.
-
Configure and enforce an appropriate
PIL.Image.MAX_IMAGE_PIXELSpolicy for inbound images, and treat decompression-bomb warnings as errors where appropriate. -
Validate source image file size and decoded pixel count before copying, converting, resizing, or adding it to a contact sheet.
-
Use process-level resource controls, such as memory limits, CPU timeouts, and disk quotas, as defense in depth.
-
Add negative tests covering excessive width, excessive height, excessive total pixel count, malformed dimensions, and large inbound images.
