From ff53d0aaab17674748625246dd285761f960cf5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 3 Aug 2026 16:38:26 +0200 Subject: [PATCH] fix(share): Avoid crash when share owner is not found MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit IShare::getNode is documented to throw only NotFoundException, so catch UserNotFoundException from the level below and wrap it. This avoids crashes from share api controller when listing shares and one of them is broken because its owner has vanished from the backend. Signed-off-by: Côme Chilliet --- lib/private/Share20/Share.php | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/private/Share20/Share.php b/lib/private/Share20/Share.php index d88710e4e191f..3ea440a885a68 100644 --- a/lib/private/Share20/Share.php +++ b/lib/private/Share20/Share.php @@ -21,6 +21,7 @@ use OCP\Share\IAttributes; use OCP\Share\IManager; use OCP\Share\IShare; +use OCP\User\Exceptions\UserNotFoundException; use Override; class Share implements IShare { @@ -135,20 +136,24 @@ public function getNode(): Node { throw new NotFoundException(); } - // for federated shares the owner can be a remote user, in this - // case we use the initiator - if ($this->userManager->userExists($this->shareOwner)) { - $userFolder = $this->rootFolder->getUserFolder($this->shareOwner); - } else { - $userFolder = $this->rootFolder->getUserFolder($this->sharedBy); - } - - $node = $userFolder->getFirstNodeById($this->fileId); - if (!$node) { - throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId); + try { + // for federated shares the owner can be a remote user, in this + // case we use the initiator + if ($this->userManager->userExists($this->shareOwner)) { + $userFolder = $this->rootFolder->getUserFolder($this->shareOwner); + } else { + $userFolder = $this->rootFolder->getUserFolder($this->sharedBy); + } + + $node = $userFolder->getFirstNodeById($this->fileId); + if (!$node) { + throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId); + } + + $this->node = $node; + } catch (UserNotFoundException $e) { + throw new NotFoundException('Owner for share not found, fileid: ' . $this->fileId, previous:$e); } - - $this->node = $node; } return $this->node;