Cannot reproduce XenForo Media Gallery 2.0.5 Error

Affected version
XenForo Media Gallery 2.0.5
I am running XenForo Media Gallery 2.0.5 and getting the following error when users are trying to upload an image:

Stack Trace:

ErrorException: [E_WARNING] json_encode(): Invalid UTF-8 sequence in argument in src/XF/Mvc/Entity/ValueFormatter.php at line 97
XF::handlePhpError()
json_encode() in src/XF/Mvc/Entity/ValueFormatter.php at line 97
XF\Mvc\Entity\ValueFormatter->encodeValueForSource() in src/XF/Mvc/Entity/Manager.php at line 721
XF\Mvc\Entity\Manager->encodeValueForSource() in src/XF/Mvc/Entity/Entity.php at line 1396
XF\Mvc\Entity\Entity->_saveToSource() in src/XF/Mvc/Entity/Entity.php at line 1135
XF\Mvc\Entity\Entity->save() in src/addons/XFMG/Service/Media/TempCreator.php at line 87
XFMG\Service\Media\TempCreator->_save() in src/XF/Service/ValidateAndSavableTrait.php at line 40
XFMG\Service\Media\TempCreator->save() in src/addons/XFMG/Attachment/Media.php at line 140
XFMG\Attachment\Media->onNewAttachment() in src/XF/Service/Attachment/Preparer.php at line 225
XF\Service\Attachment\Preparer->insertTemporaryAttachment() in src/XF/Service/Attachment/Preparer.php at line 17
XF\Service\Attachment\Preparer->insertAttachment() in src/XF/Attachment/Manipulator.php at line 171
XF\Attachment\Manipulator->insertAttachmentFromUpload() in src/XF/Pub/Controller/Attachment.php at line 88
XF\Pub\Controller\Attachment->actionUpload() in src/XF/Mvc/Dispatcher.php at line 249
XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 89
XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 41
XF\Mvc\Dispatcher->run() in src/XF/App.php at line 1931
XF\App->run() in src/XF.php at line 329
XF::runApp() in index.php at line 13

Could my server environment be causing this?

Server environment report:

You have only the minimum required PHP version. Future versions of XenForo will require a higher minimum PHP version of 5.6.0. Some features in future versions of XenForo will require a minimum PHP version of 7.1.0.

PHP version 5.4.45
MySQL version 5.6.41
Server software N/A
PHP post_max_size 64M
PHP upload_max_filesize 64M
PHP max_input_vars 1000
PHP max_execution_time 30
cURL version 7.19.7
SSL version NSS/3.27.1
Suhosin enabled No
UTC timezone Yes
Imagick support Yes
EXIF support Yes
GZip support Yes
mbstring support Yes
 
Only certain images. As an example, I can upload the attached Pooh Bear image, but not the artwork image.
 

Attachments

  • Pooh.webp
    Pooh.webp
    45.7 KB · Views: 6
  • SidewalkChalkLandscapeDownsized.webp
    SidewalkChalkLandscapeDownsized.webp
    277.8 KB · Views: 6
Are you able to upload the artwork image here, or do you get a similar error?

What is the actual file size and dimensions of the artwork image that you're uploading to your gallery? Is it exactly the same as the image above? I've tried uploading it here and it seems to work fine.

Do you have any add-ons which interact with the gallery or attachment uploads in general? Are you able to upload the artwork image to a post on your forum without issue?
 
I just attempted to upload the artwork image in the media gallery here, but I guess I don't have access to do that (is the ability to do that based on number of posts or something?). On my site, I am trying to upload the same exact artwork file that I attached previously. The size is 537 KB. The dimensions are 900 X 675. The only other add-on I have is XenForo Importers 1.0.2 (I have XenPorta 2 installed, but not active). We were able to upload the file to a post on my site, but not to the media gallery.
 
I think my issue might be a file size setting on my server. I optimized the image in Photoshop, which decreased the file size over 400 MB and I was able to upload it. I have not looked into trying to change the server settings yet, but I think that's going to be the fix for my problem here.
 
After further investigation, I believe the primary cause for this might be the handling of EXIF data.

We do attempt to convert whatever character set the EXIF data is encoded with to UTF-8 but it's possible that this wasn't taking effect on your installation.

Your steps to edit and re-save the image probably re-wrote whatever the problematic EXIF metadata was.

We attempt to override this, but it's possible you may need to add exif.encode_unicode = UTF-8 to your php.ini configuration if the issue persists. That said, with some experimentation I wasn't able to get it to fall over at all with the image you provided, even by removing various things which should make this safe.

If you have any further images which consistently trigger the problem, please let us know and we'll try and take another look. It might be worth uploading any affected images to a web accessible URL so we can be sure the upload process isn't modifying the image in any way.
 
Top Bottom