T09 · Insecure Skill Coding Practices
- Location
scripts/fit_checker.py:248- Finding
Unbounded Floorplan Allocation Enables Local Denial of Service
- Content
View full analysis
Vulnerability Details
File Location:
scripts/fit_checker.py, lines 248-250
Vulnerability Type: Uncontrolled resource consumption
Risk Level: MediumVulnerable Code
python W = max(int(round(room_w / 10)), 20) H = max(int(round(room_d / 10)), 10) grid = [[" "] * W for _ in range(H)]Technical Analysis
The
room_wandroom_dvalues originate from the command-line--roomargument and are parsed without any upper-bound or finite-number validation. When the--floorplanoption is enabled, these values directly determine the width and height of a two-dimensional character grid.The allocation grows proportionally to
W × H. An attacker or untrusted automation input can therefore provide unrealistically large room dimensions and force the process to allocate excessive memory. Exceptionally large numeric values may also convert to non-finite floating-point values, causing an uncaught exception during integer conversion.Attack Path
- An attacker supplies oversized dimensions through the
--roomargument. parse_list()accepts the syntactically valid measurements and converts them to floating-point centimeter values.- The
roomcommand performs its normal fit calculation. - With
--floorplanenabled,floorplan()derivesWandHdirectly from the attacker-controlled measurements. - The nested list allocation consumes excessive memory, potentially making the process or host unresponsive or causing operating-system termination.
Example:
bash python3 scripts/fit_checker.py room \ --item 1x1cm \ --room 10000000x10000000cm \ --floorplanImpact Assessment
Successful exploitation can cause local denial of service through memory exhaustion, severe resource pressure, process termination, or an uncaught conversion error. This is particularly relevant when an AI agent or automated service invokes the utility with measurements derived from untrusted input.
The vulnerability does not provide co ...[truncated 190 chars]
- An attacker supplies oversized dimensions through the
- Remediation
View remediation
Remediation Suggestions
- Validate every parsed measurement with
math.isfinite()and rejectNaNor infinity. - Enforce realistic maximum room dimensions before performing calculations or rendering.
- Define explicit maximum values for
W,H, and the total cell countW * H. - Use adaptive scaling so large rooms are rendered within a fixed terminal canvas rather than at a constant ten-centimeter-per-character scale.
- Return a clear validation error when the requested floorplan exceeds rendering limits.
- Defensively handle
OverflowErrorandMemoryError, while treating pre-allocation validation as the primary control. - Add regression tests covering oversized and non-finite-equivalent numeric inputs.
A hardened implementation should validate before allocation, for example:
python if not all(math.isfinite(v) and v > 0 for v in (room_w, room_d)): raise ValueError("room dimensions must be positive finite values") W = max(int(round(room_w / 10)), 20) H = max(int(round(room_d / 10)), 10) MAX_WIDTH = 240 MAX_HEIGHT = 120 MAX_CELLS = 20_000 if W > MAX_WIDTH or H > MAX_HEIGHT or W * H > MAX_CELLS: raise ValueError("room dimensions exceed floorplan rendering limits") grid = [[" "] * W for _ in range(H)]- Validate every parsed measurement with
