Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Detect aborted connection in OC\Files\View and stop writing data to the
 output buffer

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc authored and backportbot-nextcloud[bot] committed Sep 5, 2023
commit b7d82f7c0192611208d66fe8d3cab34a2d56349a
10 changes: 10 additions & 0 deletions lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ public function readfile($path) {
$chunkSize = 524288; // 512 kB chunks
while (!feof($handle)) {
echo fread($handle, $chunkSize);
$this->checkConnectionStatus();
flush();
}
fclose($handle);
Expand Down Expand Up @@ -482,6 +483,7 @@ public function readfilePart($path, $from, $to) {
$len = $chunkSize;
}
echo fread($handle, $len);
$this->checkConnectionStatus();
flush();
}
return ftell($handle) - $from;
Expand All @@ -492,6 +494,14 @@ public function readfilePart($path, $from, $to) {
return false;
}


private function checkConnectionStatus(): void {
$connectionStatus = \connection_status();
if ($connectionStatus !== 0) {
throw new \RuntimeException("Connection lost. Status: $connectionStatus");
}
}

/**
* @param string $path
* @return mixed
Expand Down
3 changes: 0 additions & 3 deletions lib/private/legacy/OC_Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,6 @@ public static function get($dir, $files, $params = null) {
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);
}
}
Expand Down