DivisionByZeroError on AspectSwitcherImageEffect

Created on 28 April 2023, about 1 year ago
Updated 8 November 2023, 8 months 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

Needs work

Version

3.0

Component

Code

Created by

🇺🇸United States robphillips

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024