Cannot reproduce Intermittent htmlspecialchars errors

nero

Member
Affected version
2.1.11
Hi there,

I'm new to Xenforo and I'm working on converting a phpBB-3.2 board to Xenforo-2.1.11.

I have intermittent errors happening about some unsupported charset error with htmlspecialchars(). Here's an example:

Fatal error: Uncaught exception 'ErrorException' with message '[E_WARNING] htmlspecialchars(): charset `����' not supported, assuming utf-8' in /dev/website/www/src/XF/Error.php:448
Stack trace:
#0 [internal function]: XF::handlePhpError(2, 'htmlspecialchar...', '/dev/website...', 448, Array)
#1 /dev/website/www/src/XF/Error.php(448): htmlspecialchars('XF::handlePhpEr...')
#2 /dev/website/www/src/XF/Error.php(377): XF\Error->getExceptionTraceHtml(Object(ErrorException))
#3 /dev/website/www/src/XF/App.php(2207): XF\Error->displayFatalExceptionMessage(Object(ErrorException))
#4 /dev/website/www/src/XF.php(168): XF\App->displayFatalExceptionMessage(Object(ErrorException))
#5 [internal function]: XF::handleException(Object(ErrorException))
#6 {main}
thrown in /dev/website/www/src/XF/Error.php on line 448

It all started during the import. It stopped several times with a similar error (same error, only the charset is changing) and re-launching the importer worked until another error happened. Eventually I managed to finalize the import and now have a working board. All messages seem OK and I don't see any encoding issue when browsing the board. But from time to time, whether it's on the public side of the board or in the admin control panel, I have this error coming back. Reloading the page fixes the issue and the page displays correctly.
For instance, I just had the error in the admin control panel at the following page: /admin.php?tools/test-image-proxy

Is there something I did wrong and could you tell me how to fix this error?

I'm running PHP-5.6 and my php.ini has the default_charset set to UTF-8.

Thanks!
 
Honestly, I'm very confused by this error. The line in question doesn't pass a charset argument (we rarely do), so it should be using the default_charset. You appear to have headed me off by mentioning that, so I don't see how this would happen. There have been a couple places where certain functions weren't truly thread safe, but the case I'm thinking of was libxml related, and thus PHP being beholden to an underlying library. That isn't the case here. Looking at the C in the PHP source, it really should be coming from the argument or falling back to the php.ini setting.

There isn't anything in the default XF code or libraries that actually tries to change default_charset either.

We have seen some situations in the past where opcode caching bugs/corruption have led to impossible execution stats, so I do wonder if that's the case here. You mention PHP 5.6 so that could be relevant -- 2.2 has just been released (and is now our preferred version) and we've just dropped support for 5.6.

So as it stands, my only idea is some bizarre server issue.
 
Hi, thanks for checking that out!

You must be right, seems to be tied with my dev environment. I did the migration again on a Xenforo test instance on the production servers and everything ran smoothly, no error at all.

I also tried with another developer that has a similar dev env as mine (we're using Apache + PHP versions from Macports on Mac OS Catalina) and she had exactly the same issues with those htmlspecialchars() errors.

I'll let you know if we find out where it comes from.

Cheers!
 
Back
Top Bottom