Skip to content

fix(converter): validate scale factor finiteness and guard against below-1-pixel dimensions in ImageResizingConverter#2169

Open
ThryLox wants to merge 1 commit into
microsoft:mainfrom
ThryLox:feat/image-resizing-dimensions-validation
Open

fix(converter): validate scale factor finiteness and guard against below-1-pixel dimensions in ImageResizingConverter#2169
ThryLox wants to merge 1 commit into
microsoft:mainfrom
ThryLox:feat/image-resizing-dimensions-validation

Conversation

@ThryLox

@ThryLox ThryLox commented Jul 12, 2026

Copy link
Copy Markdown

This PR resolves issue #2162 by adding robust input validation to ImageResizingConverter.

Description

Currently, ImageResizingConverter allows positive non-finite scale factors (such as math.nan or math.inf). Furthermore, scaling an image with a valid positive scale factor can truncate dimensions to zero (e.g., scaling a 1x1 image by 0.5), which raises an unhelpful Pillow ValueError: height and width must be > 0 deep inside the processing pipeline.

Changes

  • Imported math and added math.isfinite(scale_factor) checking to the ImageResizingConverter constructor.
  • Added validation inside _apply_transform to check that the calculated dimensions (both new_width and new_height) are at least 1 pixel, raising a clean, informative ValueError before calling Pillow.
  • Documented the raised exception in the _apply_transform docstring.
  • Added unit tests to tests/unit/converter/test_image_resizing_converter.py covering:
    • Non-finite scale factors (nan, inf, -inf).
    • Scales that result in zero-size image dimensions.

…low-1-pixel dimensions in ImageResizingConverter
@ThryLox

ThryLox commented Jul 12, 2026

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant