Skip to content

Commit

Permalink
Fix EZP-27101: Recursion protection for retrieving metadata doesn't w…
Browse files Browse the repository at this point in the history
…ork properly
  • Loading branch information
Jacek Foremski committed Jun 27, 2018
1 parent 6f4e99f commit 35cbadc
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ function metaData( $contentObjectAttribute )
$object = $this->objectAttributeContent( $contentObjectAttribute );
if ( $object )
{
if ( eZContentObject::recursionProtect( $object->attribute( 'id' ) ) )
if ( eZContentObject::stackRecursionProtect( $contentObjectAttribute->attribute( 'id' ), $object->attribute( 'id' ) ) )
{
// Does the related object exist in the same language as the current content attribute ?
if ( in_array( $contentObjectAttribute->attribute( 'language_code' ), $object->attribute( 'current' )->translationList( false, false ) ) )
Expand All @@ -651,7 +651,11 @@ function metaData( $contentObjectAttribute )
$attributes = $object->contentObjectAttributes();
}

return eZContentObjectAttribute::metaDataArray( $attributes );
eZContentObject::stackRecursionProtectionPush();
$metaDataArray = eZContentObjectAttribute::metaDataArray( $attributes );
eZContentObject::stackRecursionProtectionPop();

return $metaDataArray;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,7 @@ function metaData( $contentObjectAttribute )
$subObjectVersionNum = $subCurrentVersionObject->attribute( 'version' );
}

if ( eZContentObject::recursionProtect( $subObjectID ) )
if ( eZContentObject::stackRecursionProtect( $contentObjectAttribute->attribute( 'id' ), $subObjectID ) )
{
if ( !$subObject )
{
Expand All @@ -1626,7 +1626,10 @@ function metaData( $contentObjectAttribute )
}
}

eZContentObject::stackRecursionProtectionPush();
$attributeMetaDataArray = eZContentObjectAttribute::metaDataArray( $attributes );
eZContentObject::stackRecursionProtectionPop();

$metaDataArray = array_merge( $metaDataArray, $attributeMetaDataArray );
}

Expand Down
51 changes: 51 additions & 0 deletions kernel/classes/ezcontentobject.php
Original file line number Diff line number Diff line change
Expand Up @@ -2644,6 +2644,57 @@ static function recursionProtectionEnd()
unset( $GLOBALS["ez_content_object_recursion_protect"] );
}

private static $recursionProtectionStack;
private static $recursionProtectionCurrent;

public static function stackRecursionProtectionStart()
{
self::$recursionProtectionStack = [];
self::$recursionProtectionCurrent = [];
}

public static function stackRecursionProtect($key, $value)
{
if (self::stackRecursionExistsOnStack($key, $value))
{
return false;
}

self::$recursionProtectionCurrent[$key][] = $value;

return true;
}

private static function stackRecursionExistsOnStack($key, $value)
{
foreach (self::$recursionProtectionStack as $stackItem)
{
if (array_key_exists($key, $stackItem) && in_array($value, $stackItem[$key], true))
{
return true;
}
}

return false;
}

public static function stackRecursionProtectionPush()
{
self::$recursionProtectionStack[] = self::$recursionProtectionCurrent;
self::$recursionProtectionCurrent = [];
}

public static function stackRecursionProtectionPop()
{
self::$recursionProtectionCurrent = array_pop(self::$recursionProtectionStack);
}

public static function stackRecursionProtectionEnd()
{
self::$recursionProtectionStack = null;
self::$recursionProtectionCurrent = null;
}

/**
* Transaction unsafe. If you call several transaction unsafe methods you must enclose
* the calls within a db transaction; thus within db->begin and db->commit.
Expand Down
4 changes: 2 additions & 2 deletions kernel/search/plugins/ezsearchengine/ezsearchengine.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function addObject( $contentObject, $commit = true )
$placement = 0;
$previousWord = '';

eZContentObject::recursionProtectionStart();
eZContentObject::stackRecursionProtectionStart();
foreach ( $currentVersion->contentObjectAttributes() as $attribute )
{
$metaData = array();
Expand Down Expand Up @@ -136,7 +136,7 @@ public function addObject( $contentObject, $commit = true )
}
}
}
eZContentObject::recursionProtectionEnd();
eZContentObject::stackRecursionProtectionEnd();

$wordIDArray = $this->buildWordIDArray( array_keys( $indexArrayOnlyWords ) );

Expand Down

0 comments on commit 35cbadc

Please sign in to comment.