ZABBIX BUGS AND ISSUES

Image upload not working properly

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Cannot Reproduce
  • Affects Version/s: 1.4.5
  • Fix Version/s: None
  • Component/s: Frontend (F)
  • Labels:
    None
  • Environment:
    Centos 4.5, zabbix 1.4.6, postgres 8.2.x
    browser: tried both firefox 3 and safari
  • Zabbix ID:
    RTD

Description

When trying to create a new image (icon for map), I get the following error when trying to display the image (i.e. it uploads ok, but does not display properly):

(main text of the image, html not included)
imagecreatefromstring() :Data is not in a recognized format [image.php:58]
imagepng(): supplied argument is not a valid Image resource [/include/config.inc.php:1683]
imagedestroy(): supplied argument is not a valid Image resource [/include/config.inc.php:1683]

To reproduce:
Go to general, images. Click on one of the icons to display, right click, save as.
Go back, click create new image, give it a name, and upload the png file you just downloaded. Should see these errors, at least with a postgres backend.

Activity

Hide
Steve Ruiz added a comment -

This is what I see in place of the image I uploaded.

Show
Steve Ruiz added a comment - This is what I see in place of the image I uploaded.
Hide
Steve Ruiz added a comment -

Was able to get around this by changing line 124 in images.inc.php:

return DBexecute("insert into images (imageid,name,imagetyp e,image)". " values ($imageid,".zbx_dbstr($name).",".$i magetype.",'".$image."')");

Removed the zbx_dbstr($image) and replaced with just $image, since we already escaped it with pg_escape_bytea() function.

Show
Steve Ruiz added a comment - Was able to get around this by changing line 124 in images.inc.php: return DBexecute("insert into images (imageid,name,imagetyp e,image)". " values ($imageid,".zbx_dbstr($name).",".$i magetype.",'".$image."')"); Removed the zbx_dbstr($image) and replaced with just $image, since we already escaped it with pg_escape_bytea() function.
Hide
Julien Poumailloux added a comment -

I was able to fix the issue, the previous code given by Steve Ruiz is buggy.

in function add_image from include/images.inc.php, replace:

else if($DB['TYPE'] == "POSTGRESQL"){ $image = pg_escape_bytea($image); }

by
else if($DB['TYPE'] == "POSTGRESQL"){ $image = pg_escape_bytea($image); return DBexecute("insert into images (imageid,name,imagetype,image)". " values ($imageid,".zbx_dbstr($name).",".$imagetype.",'".$image."')"); }

the point is that postgresql expect the $image part of the request to be between quotes ', while this is not required by mysql.

Sincerely,

Julien Poummailloux

Show
Julien Poumailloux added a comment - I was able to fix the issue, the previous code given by Steve Ruiz is buggy. in function add_image from include/images.inc.php, replace: else if($DB['TYPE'] == "POSTGRESQL"){ $image = pg_escape_bytea($image); } by else if($DB['TYPE'] == "POSTGRESQL"){ $image = pg_escape_bytea($image); return DBexecute("insert into images (imageid,name,imagetype,image)". " values ($imageid,".zbx_dbstr($name).",".$imagetype.",'".$image."')"); } the point is that postgresql expect the $image part of the request to be between quotes ', while this is not required by mysql. Sincerely, Julien Poummailloux
Hide
Aron Ujvari added a comment -

I would recommend the attached patch against Zabbix 1.6.6, but the same modification should work with oldaer version also.

This is an ugly hack required for PHP's PostgreSQL interface since pg_escape_bytea and pg_unescape_bytea are not inverse functions, so we are not able to get back the same binary information from the database as we loaded before without this patch.

It also contains a fix for update_image function, as we it needs zbs_dbstr($image) but not the extra quotes to allow updates. add_image function works the same way by default, this patch changes the update_image function to this way too.

Show
Aron Ujvari added a comment - I would recommend the attached patch against Zabbix 1.6.6, but the same modification should work with oldaer version also. This is an ugly hack required for PHP's PostgreSQL interface since pg_escape_bytea and pg_unescape_bytea are not inverse functions, so we are not able to get back the same binary information from the database as we loaded before without this patch. It also contains a fix for update_image function, as we it needs zbs_dbstr($image) but not the extra quotes to allow updates. add_image function works the same way by default, this patch changes the update_image function to this way too.
Hide
Andrew Flannery added a comment -

here's my 1.8.2 patch for the same issue with mysql.

Show
Andrew Flannery added a comment - here's my 1.8.2 patch for the same issue with mysql.
Hide
gabhosh added a comment -

Here is mine for 1.8.5 for the same mysql issue
greatly inspired from the precedent patch from Andrew

Show
gabhosh added a comment - Here is mine for 1.8.5 for the same mysql issue greatly inspired from the precedent patch from Andrew
Hide
richlv added a comment -

ZBX-4044 might affect this issue

Show
richlv added a comment - ZBX-4044 might affect this issue
Hide
Jc Duss added a comment -

I've got the same troubles here with a mysql 5.1.49 and apache2.2.16
I was not affected with this problem since I upload from 1.8.3 to 1.8.8. (On 1.8.3 it was working fine).

my table images and database zabbix are set with utf8 charset.

I tried the patch for 1.8.5 here without success.

If I "tcpdump" the traffic, I can see that image is uploaded... but store in database is not done. The blob field in the tables remains empty. I tried with both PNG and JPG without success.

Can someone help me? What kind of information can I give you?

Nicolas

Show
Jc Duss added a comment - I've got the same troubles here with a mysql 5.1.49 and apache2.2.16 I was not affected with this problem since I upload from 1.8.3 to 1.8.8. (On 1.8.3 it was working fine). my table images and database zabbix are set with utf8 charset. I tried the patch for 1.8.5 here without success. If I "tcpdump" the traffic, I can see that image is uploaded... but store in database is not done. The blob field in the tables remains empty. I tried with both PNG and JPG without success. Can someone help me? What kind of information can I give you? Nicolas
Hide
richlv added a comment -

this should be fixed by now - is anybody seeing this with recent zabbix version and proper utf8 db ?

Show
richlv added a comment - this should be fixed by now - is anybody seeing this with recent zabbix version and proper utf8 db ?
Hide
Ivo Kurzemnieks added a comment -

Issue has been fixed in latest Zabbix versions and is no longer reproducible.

CLOSED.

Show
Ivo Kurzemnieks added a comment - Issue has been fixed in latest Zabbix versions and is no longer reproducible. CLOSED.

People

Vote (5)
Watch (7)

Dates

  • Created:
    Updated:
    Resolved: