DivisionByZeroError on AspectSwitcherImageEffect

Created on 28 April 2023, almost 2 years ago

Problem/Motivation

An image style using the aspect switcher effect may cause a division by zero PHP error if the source image is corrupted. Marked as major because this bug took down an important production site without warning.

The website encountered an unexpected error. Please try again later.
DivisionByZeroError: Division by zero in Drupal\image_effects\Plugin\ImageEffect\AspectSwitcherImageEffect->getChildImageStyleToExecute() (line 200 of modules/contrib/image_effects/src/Plugin/ImageEffect/AspectSwitcherImageEffect.php).

Steps to reproduce

  1. Create an image style with at least one aspect switcher effect
  2. Apply the image style to an image field display formatter (i.e. on a content type)
  3. Upload a corrupted image to the image field and save
  4. Attempt to view the image field via the display formatter

An example corrupted image is attached. It's a plain text file with a JPEG extension.

Proposed resolution

Verify the image toolkit was able to get the image dimensions before attempting to apply transformations.

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇺🇸United States robphillips

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024