summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorCôme Chilliet <91878298+come-nc@users.noreply.github.com>2023-09-07 09:31:44 +0200
committerGitHub <noreply@github.com>2023-09-07 09:31:44 +0200
commit5434b35ac7ecf1a966f6c6c8db8a422ee82a684b (patch)
tree43886d8d784a4eb13818a4ced71b8e593a7da1c7 /lib/private
parent49a6dac6c9733de17d42818ba7386198f4e187de (diff)
parent342cb33f714fccf0a404560fd43d0893763f1132 (diff)
downloadnextcloud-server-5434b35ac7ecf1a966f6c6c8db8a422ee82a684b.tar.gz
nextcloud-server-5434b35ac7ecf1a966f6c6c8db8a422ee82a684b.zip
Merge pull request #40280 from nextcloud/backport/40233/stable26
[stable26] Detect aborted connection in OC\Files\View and stop writing data to the output buffer
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Files/View.php13
-rw-r--r--lib/private/legacy/OC_Files.php7
2 files changed, 16 insertions, 4 deletions
diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php
index 95ad46ec554..0cf5e24616a 100644
--- a/lib/private/Files/View.php
+++ b/lib/private/Files/View.php
@@ -55,6 +55,7 @@ use OC\User\User;
use OCA\Files_Sharing\SharedMount;
use OCP\Constants;
use OCP\Files\Cache\ICacheEntry;
+use OCP\Files\ConnectionLostException;
use OCP\Files\EmptyFileNameException;
use OCP\Files\FileNameTooLongException;
use OCP\Files\InvalidCharacterInPathException;
@@ -427,10 +428,11 @@ class View {
}
$handle = $this->fopen($path, 'rb');
if ($handle) {
- $chunkSize = 524288; // 512 kB chunks
+ $chunkSize = 524288; // 512 kiB chunks
while (!feof($handle)) {
echo fread($handle, $chunkSize);
flush();
+ $this->checkConnectionStatus();
}
fclose($handle);
return $this->filesize($path);
@@ -483,6 +485,7 @@ class View {
}
echo fread($handle, $len);
flush();
+ $this->checkConnectionStatus();
}
return ftell($handle) - $from;
}
@@ -492,6 +495,14 @@ class View {
return false;
}
+
+ private function checkConnectionStatus(): void {
+ $connectionStatus = \connection_status();
+ if ($connectionStatus !== CONNECTION_NORMAL) {
+ throw new ConnectionLostException("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..2fa0f6d1b77 100644
--- a/lib/private/legacy/OC_Files.php
+++ b/lib/private/legacy/OC_Files.php
@@ -230,14 +230,15 @@ class OC_Files {
OC::$server->getLogger()->logException($ex);
$l = \OC::$server->getL10N('lib');
\OC_Template::printErrorPage($l->t('Cannot download file'), $ex->getMessage(), 200);
+ } catch (\OCP\Files\ConnectionLostException $ex) {
+ self::unlockAllTheFiles($dir, $files, $getType, $view, $filename);
+ OC::$server->getLogger()->logException($ex, ['level' => \OCP\ILogger::DEBUG]);
+ \OC_Template::printErrorPage('Connection lost', $ex->getMessage(), 200);
} catch (\Exception $ex) {
self::unlockAllTheFiles($dir, $files, $getType, $view, $filename);
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);
}
}