Skip to content

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

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

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

@rlundeen2 rlundeen2 self-assigned this Jul 13, 2026
@rlundeen2

Copy link
Copy Markdown
Contributor

Thx for taking a look! I was on the fence, but I think ultimately I'm going to close it. I know this is a judgement call, but I think this makes the code less readable; and ultimately it just changes the exceptions raised.

@rlundeen2 rlundeen2 closed this Jul 13, 2026
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.

2 participants