Skip to content

Commit

Permalink
Merge pull request #44132 from nextcloud/fix/share-init-recursion
Browse files Browse the repository at this point in the history
fix: don't return null for SharedStorage::getWrapperStorage with share recursion
  • Loading branch information
susnux authored Mar 14, 2024
2 parents 05d020d + f46209a commit 26c37fa
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions apps/files_sharing/lib/SharedStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto

private static int $initDepth = 0;

/**
* @psalm-suppress NonInvariantDocblockPropertyType
* @var ?\OC\Files\Storage\Storage $storage
*/
protected $storage;

public function __construct($arguments) {
$this->ownerView = $arguments['ownerView'];
$this->logger = \OC::$server->get(LoggerInterface::class);
Expand Down Expand Up @@ -135,8 +141,21 @@ private function getSourceRootInfo() {
return $this->sourceRootInfo;
}

/**
* @psalm-assert \OC\Files\Storage\Storage $this->storage
*/
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;
}

Expand Down

0 comments on commit 26c37fa

Please sign in to comment.