Warning - this is a long post, and as far as I can tell not really a Zabbix bug. But I'm seeing it after upgrading our servers to Zabbix 5.0 and would love anyone/everyone's thoughts & ideas to solve the problem.
I'm running into issues with php-gd (or libgd, more specifically) which is causing the graphs not to load properly. My server is RHEL 7 with Apache, and per the new requirements with release 5.0, I upgraded php from 5.4 to 7.4. (Had to load from REMI repos, b/c my company hasn't setup RHSCL subscriptions.)
Here's the error that I'm seeing in /var/log/httpd/error_log
I know this isn't a Zabbix-specific bug because I can recreate the segfault by running the same line (with dummy input values) on the php command line that graphs.inc.php uses to find the bounding box for drawing/writing the text onto the gd-based image:
If I change the fontfile, I get the "Problem loading glyph" error:
The imagettfbbox() function is called from the Zabbix php function "imageTextSize()" and used within another function called imageText() where you can also find the imagettftext() command (which calls to the gd library to actually draw the text onto the image). Both of these GD functions are causing issues (see initial log output, first line & last line). From un-altered graphs.inc.php:
I'm thinking libgd 2.3.0 release may be part of the issue? Here's the link to the libgd bug (that was recently patched) saying that empty strings used to cause a failure, but that the return values have been updated.
I tried downgrading PHP to 7.3 & 7.2, and I even found a release candidate of PHP-GD that got me back to v2.2.5 (with truetype font support enabled), but nothing works reliably. The only way to get the graphs to show up without fault is to truncate them to the first character of the string (image below). Sometimes 2 or 3 characters will work, but not always.

I'm back on PHP 7.4 / PHP-GD 2.3.0, and have hardcoded the graphs.inc.php file to return a standardized array value for imageTextSize() and modify the $string variable to just the first character at the top of the imageText() function.
I'm willing to try anything anyone can suggest to get this working. Thanks in advance.
I'm running into issues with php-gd (or libgd, more specifically) which is causing the graphs not to load properly. My server is RHEL 7 with Apache, and per the new requirements with release 5.0, I upgraded php from 5.4 to 7.4. (Had to load from REMI repos, b/c my company hasn't setup RHSCL subscriptions.)
Here's the error that I'm seeing in /var/log/httpd/error_log
Code:
[Mon Jun 15 09:31:50.017879 2020] [php7:warn] [pid 19761] [client //redacted//] PHP Warning: imagettfbbox(): Problem loading glyph in /usr/share/zabbix/include/graphs.inc.php on line 584, referer: http://redacted/zabbix/zabbix.php?action=charts.view&view_as=showgraph&fi lter_hostids%5B%5D=10551&filter_set=1 [Mon Jun 15 09:31:50.017941 2020] [php7:notice] [pid 19761] [client //redacted//] PHP Notice: Trying to access array offset on value of type bool in /usr/share/zabbix/include/graphs.inc.php on line 587, referer: http://redacted/zabbix/zabbix.php?action=charts.view&view_as=showgraph&fi lter_hostids%5B%5D=10551&filter_set=1 [Mon Jun 15 09:31:50.017956 2020] [php7:notice] [pid 19761] [client //redacted//] PHP Notice: Trying to access array offset on value of type bool in /usr/share/zabbix/include/graphs.inc.php on line 587, referer: http://redacted/zabbix/zabbix.php?action=charts.view&view_as=showgraph&fi lter_hostids%5B%5D=10551&filter_set=1 [Mon Jun 15 09:31:50.017969 2020] [php7:notice] [pid 19761] [client //redacted//] PHP Notice: Trying to access array offset on value of type bool in /usr/share/zabbix/include/graphs.inc.php on line 588, referer: http://redacted/zabbix/zabbix.php?action=charts.view&view_as=showgraph&fi lter_hostids%5B%5D=10551&filter_set=1 [Mon Jun 15 09:31:50.017980 2020] [php7:notice] [pid 19761] [client //redacted//] PHP Notice: Trying to access array offset on value of type bool in /usr/share/zabbix/include/graphs.inc.php on line 588, referer: http://redacted/zabbix/zabbix.php?action=charts.view&view_as=showgraph&fi lter_hostids%5B%5D=10551&filter_set=1 [Mon Jun 15 09:31:50.017990 2020] [php7:notice] [pid 19761] [client //redacted//] PHP Notice: Trying to access array offset on value of type bool in /usr/share/zabbix/include/graphs.inc.php on line 589, referer: http://redacted/zabbix/zabbix.php?action=charts.view&view_as=showgraph&fi lter_hostids%5B%5D=10551&filter_set=1 [Mon Jun 15 09:31:50.018301 2020] [php7:warn] [pid 19761] [client //redacted//] PHP Warning: imagettftext(): Problem loading glyph in /usr/share/zabbix/include/graphs.inc.php on line 539, referer: http://redacted/zabbix/zabbix.php?action=charts.view&view_as=showgraph&fi lter_hostids%5B%5D=10551&filter_set=1
Code:
(base) server:user # php -r "var_dump(imagettfbbox(9,0,'/usr/share/fonts/dejavu/DejaVuSans.ttf','2020-06-19'));" Segmentation fault (core dumped)
Code:
(base) server:user # php -r "var_dump(imagettfbbox(9,0,'/usr/share/fonts/ubuntu.ttf','2020-06-19'));" PHP Warning: imagettfbbox(): Problem loading glyph in Command line code on line 1
Code:
/**
* Draws a text on an image. Supports TrueType fonts.
*
* @param resource $image
* @param int $fontsize
* @param int $angle
* @param int $x
* @param int $y
* @param int $color a numeric color identifier from imagecolorallocate() or imagecolorallocatealpha()
* @param string $string
*/
function imageText($image, $fontsize, $angle, $x, $y, $color, $string) {
if ((preg_match(ZBX_PREG_DEF_FONT_STRING, $string) && $angle != 0) || ZBX_FONT_NAME == ZBX_GRAPH_FONT_NAME) {
$ttf = ZBX_FONTPATH.'/'.ZBX_FONT_NAME.'.ttf';
imagettftext($image, $fontsize, $angle, $x, $y, $color, $ttf, $string);
}
elseif ($angle == 0) {
$ttf = ZBX_FONTPATH.'/'.ZBX_GRAPH_FONT_NAME.'.ttf';
imagettftext($image, $fontsize, $angle, $x, $y, $color, $ttf, $string);
}
else {
$ttf = ZBX_FONTPATH.'/'.ZBX_GRAPH_FONT_NAME.'.ttf';
$size = imageTextSize($fontsize, 0, $string);
$imgg = imagecreatetruecolor($size['width'] + 1, $size['height']);
$transparentColor = imagecolorallocatealpha($imgg, 200, 200, 200, 127);
imagefill($imgg, 0, 0, $transparentColor);
imagettftext($imgg, $fontsize, 0, 0, $size['height'], $color, $ttf, $string);
$imgg = imagerotate($imgg, $angle, $transparentColor);
imagealphablending($imgg, false);
imagesavealpha($imgg, true);
imagecopy($image, $imgg, $x - $size['height'], $y - $size['width'], 0, 0, $size['height'], $size['width'] + 1);
imagedestroy($imgg);
}
}
/**
* Calculates the size of the given string.
*
* Returns the following data:
* - height - height of the text;
* - width - width of the text;
* - baseline - baseline Y coordinate (can only be used for horizontal text, can be negative).
*
* @param int $fontsize
* @param int $angle
* @param string $string
*
* @return array
*/
function imageTextSize($fontsize, $angle, $string) {
if (preg_match(ZBX_PREG_DEF_FONT_STRING, $string) && $angle != 0) {
$ttf = ZBX_FONTPATH.'/'.ZBX_FONT_NAME.'.ttf';
}
else {
$ttf = ZBX_FONTPATH.'/'.ZBX_GRAPH_FONT_NAME.'.ttf';
}
$ar = imagettfbbox($fontsize, $angle, $ttf, $string);
return [
'height' => abs($ar[1] - $ar[5]),
'width' => abs($ar[0] - $ar[4]),
'baseline' => $ar[1]
];
}
I tried downgrading PHP to 7.3 & 7.2, and I even found a release candidate of PHP-GD that got me back to v2.2.5 (with truetype font support enabled), but nothing works reliably. The only way to get the graphs to show up without fault is to truncate them to the first character of the string (image below). Sometimes 2 or 3 characters will work, but not always.
Code:
(base) server:user # php -r "var_dump(imagettfbbox(9,0,'/usr/share/fonts/ubuntu.ttf','2020-06-19'));"
PHP Warning: imagettfbbox(): Problem loading glyph in Command line code on line 1
bool(false)
(base) server:user #
(base) server:user #
(base) server:user # php -r "var_dump(imagettfbbox(9,0,'/usr/share/fonts/ubuntu.ttf','2'));"
array(8) {
[0]=>
int(0)
[1]=>
int(0)
[2]=>
int(6)
[3]=>
int(0)
[4]=>
int(6)
[5]=>
int(-8)
[6]=>
int(0)
[7]=>
int(-8)
}
(base) server:user # php -r "var_dump(imagettfbbox(9,0,'/usr/share/fonts/ubuntu.ttf','20'));"
array(8) {
[0]=>
int(0)
[1]=>
int(0)
[2]=>
int(6)
[3]=>
int(0)
[4]=>
int(6)
[5]=>
int(-8)
[6]=>
int(0)
[7]=>
int(-8)
}
(base) server:user # php -r "var_dump(imagettfbbox(9,0,'/usr/share/fonts/ubuntu.ttf','202'));"
array(8) {
[0]=>
int(0)
[1]=>
int(0)
[2]=>
int(6)
[3]=>
int(0)
[4]=>
int(6)
[5]=>
int(-8)
[6]=>
int(0)
[7]=>
int(-8)
}
(base) server:user # php -r "var_dump(imagettfbbox(9,0,'/usr/share/fonts/ubuntu.ttf','2020'));"
Segmentation fault (core dumped)
I'm back on PHP 7.4 / PHP-GD 2.3.0, and have hardcoded the graphs.inc.php file to return a standardized array value for imageTextSize() and modify the $string variable to just the first character at the top of the imageText() function.
I'm willing to try anything anyone can suggest to get this working. Thanks in advance.
Comment