Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intermittent simplexml_load_file(): I/O warning on local Joomla site

Tags:

php

joomla

I've just started getting an intermittent error on all pages of a joomla dev site I'm running on localhost.

The full warning is:

Warning: simplexml_load_file(): I/O warning : failed to load external entity "/site/language/en-GB/en-GB.xml" in /site/libraries/joomla/language/language.php on line 1354

The strange thing is that it is intermittent and a few refreshes will usually resolve the problem.

Is there a code problem that could be causing this or is it something else?

like image 425
doovers Avatar asked Dec 12 '13 04:12

doovers


2 Answers

Let me put it here just in case for somebody will google for an answer and the solution with not thread-safe libxml_disable_entity_loader(false) will not be applicable. The potential vulnerability of enabling the entity loader system-wide is shown below:

<!DOCTYPE scan [<!ENTITY test SYSTEM 
      "php://filter/read=convert.base64-encode/resource=/etc/passwd">]>
<scan>&test;</scan>

The problem caused by the lack of thread safety is explained here. Although one might either register her own entity loader with libxml_set_external_entity_loader, or use locks to protect calls to libxml_disable_entity_loader, these solutions seem a bit puzzling.

The good news is that the problem with external entities affects only the functions dealing with files (e.g. simplexml_load_file, DOMDocument::schemaValidate and like). That makes the solution straight and simple. First load file content as string and then execute the respective libxml string-oriented function.

simplexml_load_string(file_get_contents($xml));

and/or

$xml = new DOMDocument('1.0', 'UTF8');
$xml->loadXML(file_get_contents($xmlFile));
$xml->schemaValidateSource(file_get_contents($xsdFile));

Hope it helps somebody.

like image 194
Aleksei Matiushkin Avatar answered Nov 14 '22 07:11

Aleksei Matiushkin


It's early days yet to say conclusively that this fix works but it seems to have fixed it for now.

EDIT: Haven't seen any reoccurrence since making this change so I can confirm that this has resolved the problem.

add libxml_disable_entity_loader(false); to joomla's index.php

Credit goes to Corneliu on the Joomla forum for his post in this thread:

J! 3.1.6/3.2 simplexml_load_file, JForm::getInstance errors

like image 22
doovers Avatar answered Nov 14 '22 08:11

doovers