From d7e1f883d896841161e952f38f8225950d8189d3 Mon Sep 17 00:00:00 2001 From: Aljosha Papsch Date: Fri, 18 Aug 2017 14:23:43 +0200 Subject: [PATCH 1/2] XmlDriver: Avoid PHP bug #62577 by avoiding simplexml_load_file. Doctrine is affected by PHP bug #62577. simplexml_load_file is not able to load files if libxml_disable_entity_loader(true) has been called. simplexml_load_file fails with the message: I/O warning : failed to load external entity "/my/mappings/my_entity.dcm.xml" in /path-to/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php on line 711 This error occurs even if there are no external entities in the XML file. Waiting for the PHP bug to be resolved is infeasible, because it is unresolved since years. Therefore Doctrine needs to circumvent the bug by replacing simplexml_load_file with simplexml_load_string while getting the file contents itself. simplexml_load_string is not affected by the PHP bug. --- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index c917eb245..37b0f9522 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -811,7 +811,7 @@ class XmlDriver extends FileDriver protected function loadMappingFile($file) { $result = array(); - $xmlElement = simplexml_load_file($file); + $xmlElement = simplexml_load_string(file_get_contents($file)); if (isset($xmlElement->entity)) { foreach ($xmlElement->entity as $entityElement) { From 0de69e5a80b49cbee12dbd597d8d8d161718ebc3 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 18 Aug 2017 21:08:14 +0200 Subject: [PATCH 2/2] #6633 #3788 documenting why `simplexml_load_file()` was not used --- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 37b0f9522..7a6d4b135 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -811,6 +811,7 @@ class XmlDriver extends FileDriver protected function loadMappingFile($file) { $result = array(); + // Note: we do not use `simplexml_load_file()` because of https://bugs.php.net/bug.php?id=62577 $xmlElement = simplexml_load_string(file_get_contents($file)); if (isset($xmlElement->entity)) {