Skip to content

Comments

[5.x] Throw UnableToReadFile for invalid images in ImageGenerator#14043

Open
mmodler wants to merge 2 commits intostatamic:5.xfrom
mmodler:fix/thumbnail-invalid-image-500
Open

[5.x] Throw UnableToReadFile for invalid images in ImageGenerator#14043
mmodler wants to merge 2 commits intostatamic:5.xfrom
mmodler:fix/thumbnail-invalid-image-500

Conversation

@mmodler
Copy link
Contributor

@mmodler mmodler commented Feb 24, 2026

Description

The validateImage() method in ImageGenerator throws a generic \Exception when an image fails validation (invalid extension or MIME type mismatch). This exception is not caught by ThumbnailController::generate(), which only catches UnableToReadFile, resulting in a 500 Internal Server Error for what is essentially a "file not usable" scenario (e.g. corrupted uploads, non-image files with image extensions).

By throwing UnableToReadFile instead, the exception is now caught by the existing catch block in ThumbnailController and converted to a 404, consistent with other file-not-found scenarios.

Changes

  • ImageGenerator::validateImage(): Throw UnableToReadFile::fromLocation() instead of generic \Exception
  • Added test to verify UnableToReadFile is thrown when image validation fails

Notes

The same gap exists in the 6.x branch — happy to open a separate PR there if preferred.

The validateImage() method threw a generic \Exception when an image
failed validation, which was not caught by ThumbnailController and
resulted in a 500 error. By throwing UnableToReadFile instead, it
is now caught and converted to a 404, consistent with other
file-not-found scenarios.
@mmodler mmodler changed the base branch from 6.x to 5.x February 24, 2026 09:38
@mmodler mmodler marked this pull request as draft February 24, 2026 11:38
@mmodler mmodler marked this pull request as ready for review February 24, 2026 11:39
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