{"record":{"id":"1949289aee438aa0","repo":"Comfy-Org/ComfyUI","slug":"invalid-image-dimensions-w-x-h","errorCode":null,"errorMessage":"Invalid image dimensions: {w}x{h}","messagePattern":"Invalid image dimensions: (.+?)x(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/util/validation_utils.py","lineNumber":46,"sourceCode":"    if max_width is not None and width > max_width:\n        raise ValueError(f\"Image width must be at most {max_width}px, got {width}px\")\n    if min_height is not None and height < min_height:\n        raise ValueError(f\"Image height must be at least {min_height}px, got {height}px\")\n    if max_height is not None and height > max_height:\n        raise ValueError(f\"Image height must be at most {max_height}px, got {height}px\")\n\n\ndef validate_image_aspect_ratio(\n    image: torch.Tensor,\n    min_ratio: tuple[float, float] | None = None,  # e.g. (1, 4)\n    max_ratio: tuple[float, float] | None = None,  # e.g. (4, 1)\n    *,\n    strict: bool = True,  # True -> (min, max); False -> [min, max]\n) -> float:\n    \"\"\"Validates that image aspect ratio is within min and max. If a bound is None, that side is not checked.\"\"\"\n    w, h = get_image_dimensions(image)\n    if w <= 0 or h <= 0:\n        raise ValueError(f\"Invalid image dimensions: {w}x{h}\")\n    ar = w / h\n    _assert_ratio_bounds(ar, min_ratio=min_ratio, max_ratio=max_ratio, strict=strict)\n    return ar\n\n\ndef validate_images_aspect_ratio_closeness(\n    first_image: torch.Tensor,\n    second_image: torch.Tensor,\n    min_rel: float,  # e.g. 0.8\n    max_rel: float,  # e.g. 1.25\n    *,\n    strict: bool = False,  # True -> (min, max); False -> [min, max]\n) -> float:\n    \"\"\"\n    Validates that the two images' aspect ratios are 'close'.\n    The closeness factor is C = max(ar1, ar2) / min(ar1, ar2)  (C >= 1).\n    We require C <= limit, where limit = max(max_rel, 1.0 / min_rel).\n","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/util/validation_utils.py#L28-L64","documentation":"ValueError from validate_image_aspect_ratio when either dimension of the image is <= 0. After get_image_dimensions returns (w, h), a non-positive width or height means the tensor is degenerate (empty batch slice, zero-size dim) and the ratio computation w/h would divide by zero or be meaningless, so it refuses to compute an aspect ratio.","triggerScenarios":"Passing a tensor with a 0-sized dimension (e.g., image[:, :, :0, :] after a bad crop, or an empty batch indexed as image[i] on a 0-batch tensor) to validate_image_aspect_ratio.","commonSituations":"Bad crop/slice parameters producing zero-size dimensions; empty tensors from a failed upstream generation; off-by-one slicing bugs in custom nodes.","solutions":["Check tensor.shape for zero dims before calling the validator.","Fix the upstream crop/slice logic that produced a zero-sized dimension.","Guard custom nodes: skip or error clearly when any dim is 0 instead of passing the tensor on."],"exampleFix":"# before\nvalidate_image_aspect_ratio(image, min_ratio=(1, 4))\n# after\nassert image.shape[-2] > 0 and image.shape[-3] > 0, \"empty image\"\nvalidate_image_aspect_ratio(image, min_ratio=(1, 4))","handlingStrategy":"validation","validationCode":"def has_positive_dims(image: torch.Tensor) -> bool:\n    h = image.shape[1] if image.dim() == 4 else image.shape[0]\n    w = image.shape[2] if image.dim() == 4 else image.shape[1]\n    return h > 0 and w > 0","typeGuard":"def is_usable_image(t: torch.Tensor) -> bool:\n    return isinstance(t, torch.Tensor) and t.dim() in (3, 4) and min(t.shape[-2], t.shape[-3]) > 0","tryCatchPattern":null,"preventionTips":["Assert non-zero dimensions after crops/slices","Guard against empty batch indexing in custom nodes"],"tags":["validation","image","tensor","shape"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}