From b7d82f7c0192611208d66fe8d3cab34a2d56349a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 4 Sep 2023 14:56:06 +0200 Subject: [PATCH] Detect aborted connection in OC\Files\View and stop writing data to the output buffer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/private/Files/View.php | 10 ++++++++++ lib/private/legacy/OC_Files.php | 3 --- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index 95ad46ec554..ee4f01eaed4 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -430,6 +430,7 @@ class View { $chunkSize = 524288; // 512 kB chunks while (!feof($handle)) { echo fread($handle, $chunkSize); + $this->checkConnectionStatus(); flush(); } fclose($handle); @@ -482,6 +483,7 @@ class View { $len = $chunkSize; } echo fread($handle, $len); + $this->checkConnectionStatus(); flush(); } return ftell($handle) - $from; @@ -492,6 +494,14 @@ class View { return false; } + + private function checkConnectionStatus(): void { + $connectionStatus = \connection_status(); + if ($connectionStatus !== 0) { + throw new \RuntimeException("Connection lost. Status: $connectionStatus"); + } + } + /** * @param string $path * @return mixed diff --git a/lib/private/legacy/OC_Files.php b/lib/private/legacy/OC_Files.php index 5655139b24a..92768fa8af2 100644 --- a/lib/private/legacy/OC_Files.php +++ b/lib/private/legacy/OC_Files.php @@ -235,9 +235,6 @@ class OC_Files { OC::$server->getLogger()->logException($ex); $l = \OC::$server->getL10N('lib'); $hint = method_exists($ex, 'getHint') ? $ex->getHint() : ''; - if ($event && $event->getErrorMessage() !== null) { - $hint .= ' ' . $event->getErrorMessage(); - } \OC_Template::printErrorPage($l->t('Cannot download file'), $hint, 200); } }