Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-27101: Recursion protection for retrieving metadata doesn't work properly #1371

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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