Problem/Motivation

Drupal version is 10.2.4, PHP is 8.3.

[warning] imagecreatefrompng(): gd-png: fatal libpng error: Read Error: truncated data
> GDToolkit.php:271
> [warning] imagecreatefrompng(): gd-png error: setjmp returns error condition 3
> GDToolkit.php:271
> [warning] imagecreatefrompng(): "azblob://inline-images/consumer-goods.png" is not a valid PNG file GDToolkit.php:271
> [warning] The image toolkit 'gd' failed processing 'scale' for image 'azblob://inline-images/consumer-goods.png'. Reported error: TypeError - Drupal\system\Plugin\ImageToolkit\GDToolkit::setImage(): Argument #1 ($image) must be of type ?GdImage, false given, called in /var/www/html/localhost/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php on line 284
> [error] Image scale failed using the gd toolkit on azblob://inline-images/consumer-goods.png (image/png, 1319x1022)
> [warning] imagecreatefrompng(): gd-png: fatal libpng error: Read Error: truncated data
> GDToolkit.php:271
> [warning] imagecreatefrompng(): gd-png error: setjmp returns error condition 3
> GDToolkit.php:271
> [warning] imagecreatefrompng(): "azblob://inline-images/consumer-goods.png" is not a valid PNG file GDToolkit.php:271
[error] TypeError: Drupal\system\Plugin\ImageToolkit\GDToolkit::setImage(): Argument #1 ($image) must be of type ?GdImage, false given, called in /var/www/html/localhost/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php on line 284 in Drupal\system\Plugin\ImageToolkit\GDToolkit->setImage() (line 201 of /var/www/html/localhost/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php) #0 /var/www/html/localhost/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php(284): Drupal\system\Plugin\ImageToolkit\GDToolkit->setImage()

Proposed resolution

Add checking for boolean result of the function.

Remaining tasks

Review my PR, give feedback, merge if possible.

CommentFileSizeAuthor
#2 3483541.patch807 bytesradheymkumar

Comments

radheymkumar created an issue. See original summary.

radheymkumar’s picture

Category: Bug report » Task
Status: Active » Needs review
StatusFileSize
new807 bytes

Attaching initial patch file.

smustgrave’s picture

Version: 10.2.x-dev » 11.x-dev
Category: Task » Bug report
Status: Needs review » Needs work
Issue tags: +Needs tests, +Needs steps to reproduce

Fixes should be in MRs vs patches.

Issue summary appears to be incomplete, missing steps to reproduce

Also will need test coverage.

nayanalok’s picture

Hi, I am getting similar error on Drupal 10.4.2 only line numbers are different.

TypeError: Drupal\system\Plugin\ImageToolkit\GDToolkit::setImage(): Argument #1 ($image) must be of type ?GdImage, bool given

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.