Skip to content

Commit cb2a6d6

Browse files
committed
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>
1 parent 79c2353 commit cb2a6d6

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

lib/private/Files/View.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ public function readfile($path) {
428428
$chunkSize = 524288; // 512 kB chunks
429429
while (!feof($handle)) {
430430
echo fread($handle, $chunkSize);
431+
$this->checkConnectionStatus();
431432
flush();
432433
}
433434
fclose($handle);
@@ -480,6 +481,7 @@ public function readfilePart($path, $from, $to) {
480481
$len = $chunkSize;
481482
}
482483
echo fread($handle, $len);
484+
$this->checkConnectionStatus();
483485
flush();
484486
}
485487
return ftell($handle) - $from;
@@ -490,6 +492,14 @@ public function readfilePart($path, $from, $to) {
490492
return false;
491493
}
492494

495+
496+
private function checkConnectionStatus(): void {
497+
$connectionStatus = \connection_status();
498+
if ($connectionStatus !== 0) {
499+
throw new \RuntimeException("Connection lost. Status: $connectionStatus");
500+
}
501+
}
502+
493503
/**
494504
* @param string $path
495505
* @return mixed
@@ -1053,7 +1063,6 @@ public function toTmpFile($path) {
10531063
public function fromTmpFile($tmpFile, $path) {
10541064
$this->assertPathLength($path);
10551065
if (Filesystem::isValidPath($path)) {
1056-
10571066
// Get directory that the file is going into
10581067
$filePath = dirname($path);
10591068

@@ -1809,7 +1818,6 @@ private function assertPathLength($path) {
18091818
* @return boolean
18101819
*/
18111820
private function targetIsNotShared(IStorage $targetStorage, string $targetInternalPath) {
1812-
18131821
// note: cannot use the view because the target is already locked
18141822
$fileId = (int)$targetStorage->getCache()->getId($targetInternalPath);
18151823
if ($fileId === -1) {

lib/private/legacy/OC_Files.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,6 @@ public static function get($dir, $files, $params = null) {
238238
OC::$server->getLogger()->logException($ex);
239239
$l = \OC::$server->getL10N('lib');
240240
$hint = method_exists($ex, 'getHint') ? $ex->getHint() : '';
241-
if ($event && $event->getErrorMessage() !== null) {
242-
$hint .= ' ' . $event->getErrorMessage();
243-
}
244241
\OC_Template::printErrorPage($l->t('Cannot download file'), $hint, 200);
245242
}
246243
}

0 commit comments

Comments
 (0)