From 2d648ed0eb301ed35db568071325bdc7e0428eb9 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Wed, 17 Jun 2015 15:06:50 +0200 Subject: [PATCH 1/2] Verify if path exists We need to verify if the specified path exists to gracefully prevent errors. --- apps/files_sharing/ajax/publicpreview.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apps/files_sharing/ajax/publicpreview.php b/apps/files_sharing/ajax/publicpreview.php index 7685cda9d7..fff1a60b24 100644 --- a/apps/files_sharing/ajax/publicpreview.php +++ b/apps/files_sharing/ajax/publicpreview.php @@ -63,6 +63,11 @@ $view = new \OC\Files\View('/' . $userId . '/files'); $pathId = $linkedItem['file_source']; $path = $view->getPath($pathId); + +if($path === null) { + throw new \OCP\Files\NotFoundException(); +} + $pathInfo = $view->getFileInfo($path); $sharedFile = null; From 414896d8a095d93ebd4d8cd76981392c7b19f9a2 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Wed, 17 Jun 2015 15:36:54 +0200 Subject: [PATCH 2/2] Throw nicer error message instead 500 --- apps/files_sharing/ajax/publicpreview.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/files_sharing/ajax/publicpreview.php b/apps/files_sharing/ajax/publicpreview.php index fff1a60b24..0734c8c115 100644 --- a/apps/files_sharing/ajax/publicpreview.php +++ b/apps/files_sharing/ajax/publicpreview.php @@ -65,7 +65,9 @@ $pathId = $linkedItem['file_source']; $path = $view->getPath($pathId); if($path === null) { - throw new \OCP\Files\NotFoundException(); + \OC_Response::setStatus(\OC_Response::STATUS_NOT_FOUND); + \OC_Log::write('core-preview', 'Could not resolve file for shared item', OC_Log::WARN); + exit; } $pathInfo = $view->getFileInfo($path);