News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Uncaught ImagickException: unable to open image

Started by sah62, February 15, 2023, 09:33:54 AM

Previous topic - Next topic

sah62

Every so often I see one of these errors in my forum's error log:

Quotehttps://www.mysite.com/smf/index.php?board=3.0
/var/www/mysite/smf/Sources/Subs-Attachments.php (Line 1255)  Backtrace information

Type of error: General
2: Trying to access array offset on value of type bool

1254                                                 // What about the extension?
1255                                                 $thumb_ext = isset($context['valid_image_types'][$size[2]]) ? $context['valid_image_types'][$size[2]] : '';

The issue here is that the value of $size is boolean false. It's set on line 1246:

1246                                                 $size = @getimagesize($filename . '_thumb');

The getimagesize function can return false on error. Digging deeper, I found this error in my web server log:

Quote2023/02/14 19:03:12 [error] 1951957#1951957: *246023 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught ImagickException: unable to open image `/var/www/mysite/smf/attachments/675828_5d4697c2b7e02ce4e76839b86dbea4bec0740dce.dat_thumb.tmp': No such file or directory @ error/blob.c/OpenBlob/2924 in /var/www/mysite/smf/Sources/Subs-Graphics.php:437
Stack trace:
#0 /var/www/mysite/smf/Sources/Subs-Graphics.php(437): Imagick->__construct()
#1 /var/www/mysite/smf/Sources/Subs-Graphics.php(383): resizeImage()
#2 /var/www/mysite/smf/Sources/Subs-Graphics.php(147): resizeImageFile()
#3 /var/www/mysite/smf/Sources/Subs-Attachments.php(1231): createThumbnail()
#4 /var/www/mysite/smf/Sources/Subs-Attachments.php(1048): loadAttachmentContext()
#5 /var/www/mysite/smf/Sources/Subs.php(1746): parseAttachBBC()
#6 /var/www/mysite/smf/Sources/Subs.php(3643): {closure}()
#7 /var/www/mysite/smf/Sources/MessageIndex.php(395): parse_bbc()
#8 /var/www/mysite/smf/index.php(191): MessageIndex()
#9 {main}
  thrown in /var/www/mysite/smf/Sources/Subs-Graphics.php on line 437" while reading response header from upstream, client: 70.44.52.59, server: www.mysite.com, request: "GET /smf/index.php?board=3.0 HTTP/1.1", upstream: "fastcgi://unix:/run/php/php-fpm-mysite.sock:", host: "www.mysite.com"

437                         $imagick = New Imagick($destName);

My question: how can this call fail when there are other function calls prior to this that open and read information from this very same file? When I look right now, the .dat file exists. The .dat_thumb and .dat_thumb.tmp files don't.

Advertisement: