Skip to content

BUG ImageResizingConverter can produce zero-sized output dimensions #2162

Description

@akshan-main

Describe the bug

ImageResizingConverter accepts positive scale factors that can truncate the output width or height to 0, causing Pillow to raise ValueError: height and width must be > 0. It also accepts non-finite values such as nan and inf.

Steps/Code to Reproduce

from PIL import Image
from pyrit.prompt_converter import ImageResizingConverter

ImageResizingConverter(scale_factor=0.5)._apply_transform(
    Image.new("RGB", (1, 1))

Fix

Reject non-finite scale factors and raise a clear ValueError before calling Pillow when either calculated dimension is below one pixel.

I would like to submit a focused fix with unit tests.

@romanlutz

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions