From 5f8b9996ea0677e900c202aa9406b44e89755e5c Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Sat, 2 Nov 2024 14:02:09 +0100 Subject: [PATCH] TASK: Guards against recursion in get content repository and memory overflow --- .../Classes/Factory/ContentRepositoryFactory.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Neos.ContentRepository.Core/Classes/Factory/ContentRepositoryFactory.php b/Neos.ContentRepository.Core/Classes/Factory/ContentRepositoryFactory.php index d424f39138e..1e676265a25 100644 --- a/Neos.ContentRepository.Core/Classes/Factory/ContentRepositoryFactory.php +++ b/Neos.ContentRepository.Core/Classes/Factory/ContentRepositoryFactory.php @@ -74,6 +74,9 @@ public function __construct( $this->projectionsAndCatchUpHooks = $projectionsAndCatchUpHooksFactory->build($this->projectionFactoryDependencies); } + // guards against recursion and memory overflow + private bool $isBuilding = false; + // The following properties store "singleton" references of objects for this content repository private ?ContentRepository $contentRepository = null; private ?EventPersister $eventPersister = null; @@ -89,6 +92,10 @@ public function getOrBuild(): ContentRepository if ($this->contentRepository) { return $this->contentRepository; } + if ($this->isBuilding) { + throw new \RuntimeException(sprintf('Content repository "%s" was attempted to be build in recursion.', $this->contentRepositoryId->value), 1730552199); + } + $this->isBuilding = true; $contentGraphReadModel = $this->projectionsAndCatchUpHooks->contentGraphProjection->getState(); $commandHandlingDependencies = new CommandHandlingDependencies($contentGraphReadModel); @@ -127,7 +134,7 @@ public function getOrBuild(): ContentRepository ) ); - return $this->contentRepository = new ContentRepository( + $this->contentRepository = new ContentRepository( $this->contentRepositoryId, $publicCommandBus, $this->projectionFactoryDependencies->eventStore, @@ -141,6 +148,8 @@ public function getOrBuild(): ContentRepository $this->clock, $contentGraphReadModel ); + $this->isBuilding = false; + return $this->contentRepository; } /**