Skip to content

Commit 3f053f8

Browse files
Piskvorfranmomu
authored andcommitted
If libxml_disable_entity_loader(true), simplexml_load_file() fails;
this avoids the limitation by avoiding file operations in libXML. The only difference here is that the file operations are done via file_get_contents() and the resulting string is passed to simplexml_load_string() from PHP, instead of simplexml_load_file() doing these two things internally.
1 parent 3bdde9e commit 3f053f8

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ a release.
2020

2121
## [Unreleased]
2222
### Fixed
23+
- `Gedmo\Mapping\Driver\Xml::_loadMappingFile()` behavior in scenarios where `libxml_disable_entity_loader(true)` was previously
24+
called.
2325
- Loggable: Missing support for `versioned` fields at `attribute-override` in XML mapping.
2426

2527
## [3.3.0] - 2021-11-15

src/Mapping/Driver/Xml.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ protected function _isAttributeSet(SimpleXmlElement $node, $attributeName)
8484
protected function _loadMappingFile($file)
8585
{
8686
$result = [];
87-
$xmlElement = simplexml_load_file($file);
87+
// We avoid calling `simplexml_load_file()` in order to prevent file operations in libXML.
88+
// If `libxml_disable_entity_loader(true)` is called before, `simplexml_load_file()` fails,
89+
// that's why we use `simplexml_load_string()` instead.
90+
// @see https://bugs.php.net/bug.php?id=62577.
91+
$xmlElement = simplexml_load_string(file_get_contents($file));
8892
$xmlElement = $xmlElement->children(self::DOCTRINE_NAMESPACE_URI);
8993

9094
if (isset($xmlElement->entity)) {

0 commit comments

Comments
 (0)