From f5e94a3dcf89ec50a41db95e6d621b5aa80c7808 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 | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/lib/private/Share20/Share.php b/lib/private/Share20/Share.php index 7593ff45636de..06d36821b9c84 100644 --- a/lib/private/Share20/Share.php +++ b/lib/private/Share20/Share.php @@ -5,8 +5,10 @@ * SPDX-FileCopyrightText: 2016 ownCloud, Inc. * SPDX-License-Identifier: AGPL-3.0-only */ + namespace OC\Share20; +use OC\User\NoUserException; use OCP\Constants; use OCP\Files\Cache\ICacheEntry; use OCP\Files\File; @@ -158,20 +160,24 @@ public function getNode() { 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); + 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 (NoUserException $e) { + throw new NotFoundException('Owner for share not found, fileid: ' . $this->fileId, previous:$e); } - - $node = $userFolder->getFirstNodeById($this->fileId); - if (!$node) { - throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId); - } - - $this->node = $node; } return $this->node;