From 22596234fcd65134487d844ac38e2e7860debbc3 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 11 Mar 2024 17:07:49 +0100 Subject: [PATCH 1/2] fix: don't return null for SharedStorage::getWrapperStorage with share recursion Signed-off-by: Robin Appelman --- apps/files_sharing/lib/SharedStorage.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/apps/files_sharing/lib/SharedStorage.php b/apps/files_sharing/lib/SharedStorage.php index f41891c67f34b..44ec877c52c10 100644 --- a/apps/files_sharing/lib/SharedStorage.php +++ b/apps/files_sharing/lib/SharedStorage.php @@ -136,6 +136,16 @@ private function getSourceRootInfo() { private function init() { if ($this->initialized) { + if (!$this->storage) { + // marked as initialized but no storage set + // this is probably because some code path has caused recursion during the share setup + // we setup a "failed storage" so `getWrapperStorage` doesn't return null. + // If the share setup completes after this the "failed storage" will be overwritten by the correct one + $this->logger->warning('Possible share setup recursion detected'); + $this->storage = new FailedStorage(['exception' => new \Exception('Possible share setup recursion detected')]); + $this->cache = new FailedCache(); + $this->rootPath = ''; + } return; } From e0f3de81509d625b90d2f9ac94d2df944cf68957 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 11 Mar 2024 17:21:29 +0100 Subject: [PATCH 2/2] chore: improve typing for SharedStorage::$storage Signed-off-by: Robin Appelman --- apps/files_sharing/lib/SharedStorage.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/apps/files_sharing/lib/SharedStorage.php b/apps/files_sharing/lib/SharedStorage.php index 44ec877c52c10..e7277323d8197 100644 --- a/apps/files_sharing/lib/SharedStorage.php +++ b/apps/files_sharing/lib/SharedStorage.php @@ -97,6 +97,12 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto private string $sourcePath = ''; + /** + * @psalm-suppress NonInvariantDocblockPropertyType + * @var ?\OC\Files\Storage\Storage $storage + */ + protected $storage; + private static int $initDepth = 0; public function __construct($arguments) { @@ -134,6 +140,9 @@ private function getSourceRootInfo() { return $this->sourceRootInfo; } + /** + * @psalm-assert \OC\Files\Storage\Storage $this->storage + */ private function init() { if ($this->initialized) { if (!$this->storage) {