smart-media
smart-media copied to clipboard
Division by zero when an image size has a height of 0, affects WooCommerce
The \HM\Media\Cropper\nearest_defined_crop_size()
function triggers a division by zero warning if one of the registered image sizes has a height
property of 0.
This affects WooCommerce which registers image sizes such as woocommerce_single
with a height
of 0, although I couldn't immediately trace the root cause or reason it does so.
Should the array map callback in nearest_defined_crop_size()
return 1 when the height is 0?

A zero value for width or height should probably mean we try and calculate the intrinsic height and use that value first. Any thoughts on that @goldenapples ?
@goldenapples some input here will be helpful if you have any?
I think we can move forward without bothering Than, it’s a clear bug that we could do with addressing in the function mentioned in the original comment here
Yeah, I also can't think of why an image size would be registered with 0 as a dimension. But it seems safe to ignore that value if it exists in the nearest crop sizes.
Zero is a shorthand for any size - only used sense for non cropped sizes.
I'm unable to replicate this issue at the moment. Will loop back to it at a later stage. Unless anyone has clearer steps to replicate?
We had this issue on a client project that is upgrading PHP from 7.4 to 8. In 7.4, this throws a warning, but in PHP 8 this throws a fatal error.

In our instance, problem was being caused by requesting the image at an undefined size (post-thumbnail
was being used but had not been set). Switching to a valid image size resolved the issue.
@mikelittle might be worth fixing this soon with folks updating to PHP 8