Fixed ErrorException: json_encode(): Invalid UTF-8 sequence

-GR-

Well-known member
Affected version
2.X
I am getting this error after a fresh upgrade from the latest 1.5 which was working fine. It is the same error with both beta 1 and beta 2 for us. Here is the error report as it shows on the XF server log.

ErrorException: json_encode(): Invalid UTF-8 sequence in argument src/XF/Mvc/Entity/Manager.php:643

Code:
#0 [internal function]: XF::handlePhpError(2, 'json_encode(): ...', '/home/***/web/...', 643, Array)
#1 /home/tfan/web/***.com/public_html/src/XF/Mvc/Entity/Manager.php(643): json_encode(Array)
#2 /home/tfan/web/***.com/public_html/src/XF/Mvc/Entity/Entity.php(1697): XF\Mvc\Entity\Manager->getEntitySourceValue(65552, Array)
#3 /home/tfan/web/***.com/public_html/src/XF/Mvc/Entity/Entity.php(1448): XF\Mvc\Entity\Entity->_saveToSource()
#4 /home/tfan/web/***.com/public_html/src/addons/XFMG/Service/Media/TempCreator.php(87): XF\Mvc\Entity\Entity->save()
#5 /home/tfan/web/***.com/public_html/src/XF/Service/ValidateAndSavableTrait.php(40): XFMG\Service\Media\TempCreator->_save()
#6 /home/tfan/web/***.com/public_html/src/addons/XFMG/Attachment/Media.php(121): XFMG\Service\Media\TempCreator->save()
#7 /home/tfan/web/***.com/public_html/src/XF/Service/Attachment/Preparer.php(219): XFMG\Attachment\Media->onNewAttachment(Object(XF\Entity\Attachment), Object(XF\FileWrapper))
#8 /home/tfan/web/***.com/public_html/src/XF/Service/Attachment/Preparer.php(17): XF\Service\Attachment\Preparer->insertTemporaryAttachment(Object(XFMG\Attachment\Media), Object(XF\Entity\AttachmentData), '4a92e962b8ff66e...', Object(XF\FileWrapper))
#9 /home/tfan/web/***.com/public_html/src/XF/Attachment/Manipulator.php(171): XF\Service\Attachment\Preparer->insertAttachment(Object(XFMG\Attachment\Media), Object(XF\FileWrapper), Object(XFRM\XF\Entity\User), '4a92e962b8ff66e...')
#10 /home/tfan/web/***.com/public_html/src/XF/Pub/Controller/Attachment.php(86): XF\Attachment\Manipulator->insertAttachmentFromUpload(Object(XF\Http\Upload), NULL)
#11 /home/tfan/web/***.com/public_html/src/XF/Mvc/Dispatcher.php(232): XF\Pub\Controller\Attachment->actionUpload(Object(XF\Mvc\ParameterBag))
#12 /home/tfan/web/***.com/public_html/src/XF/Mvc/Dispatcher.php(85): XF\Mvc\Dispatcher->dispatchClass('XF:Attachment', 'upload', 'json', Object(XF\Mvc\ParameterBag), '')
#13 /home/tfan/web/***.com/public_html/src/XF/Mvc/Dispatcher.php(41): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#14 /home/tfan/web/***.com/public_html/src/XF/App.php(1777): XF\Mvc\Dispatcher->run()
#15 /home/tfan/web/***.com/public_html/src/XF.php(320): XF\App->run()
#16 /home/tfan/web/***.com/public_html/index.php(13): XF::runApp('XF\\Pub\\App')
#17 {main}

PHP:
array(4) {
  ["url"] => string(106) "/index.php?attachments/upload&type=xfmg_media&context[category_id]=1&hash=4a92e962b8ff66ec37c41e510849dccc"
  ["referrer"] => string(76) "http://***.com/index.php?media/categories/example-category.1/add"
  ["_GET"] => array(4) {
    ["attachments/upload"] => string(0) ""
    ["type"] => string(10) "xfmg_media"
    ["context"] => array(1) {
      ["category_id"] => string(1) "1"
    }
    ["hash"] => string(32) "4a92e962b8ff66ec37c41e510849dccc"
  }
  ["_POST"] => array(11) {
    ["_xfToken"] => string(8) "********"
    ["_xfResponseType"] => string(4) "json"
    ["_xfWithData"] => string(1) "1"
    ["flowChunkNumber"] => string(1) "1"
    ["flowChunkSize"] => string(10) "4294967296"
    ["flowCurrentChunkSize"] => string(6) "775702"
    ["flowTotalSize"] => string(6) "775702"
    ["flowIdentifier"] => string(19) "775702-Jellyfishjpg"
    ["flowFilename"] => string(13) "Jellyfish.jpg"
    ["flowRelativePath"] => string(13) "Jellyfish.jpg"
    ["flowTotalChunks"] => string(1) "1"
  }
}
 
It's likely to be dodgy EXIF metadata, but also likely that we're not handling it properly.

If you could provide a copy of the image, that would be appreciated. If it's below a certain size then it should be possible to upload it here without it being resized.
 
It's likely to be dodgy EXIF metadata, but also likely that we're not handling it properly.

If you could provide a copy of the image, that would be appreciated. If it's below a certain size then it should be possible to upload it here without it being resized.

Chris,
I attached the image. It is one of the defaults in the Windows 7 image library.
 

Attachments

  • Jellyfish.webp
    Jellyfish.webp
    52.9 KB · Views: 4
Chris,
I just tried an image from my google photos which was taken with my phone and it worked fine. So it isn't a big deal technically. Don't think too many people will be trying to upload default images from their Windows machine LOL.
 
On the contrary, that does appear to be the first thing most people do :) I've seen that jelly fish and the koala one many times ;)
 
On the contrary, that does appear to be the first thing most people do :) I've seen that jelly fish and the koala one many times ;)

LOL, I guess more people do random testing like me than I think.

It's only occurring with the beta, was fine before upgrading to 2.0
 
There were some protections against invalid EXIF data in XFMG 1.x.

However, the jellyfish image doesn't appear to have any. Its data may have been stripped during upload here or there may be some other issue. We'll look into it though, thanks.
 
I haven't been able to reproduce the issue with the sample image.

Are you able to upload it to the Gallery here without error?

Could you try adding the image to a zip file and then uploading it to a post?
 
In lieu of being able to reproduce this, I have added some code which existed in XFMG 1.x but not in XF 2.x which should avoid this error. It is most likely why the same image errors in XFMG 2.0 but not in XFMG 1.x.
 
Top Bottom