Skip to content
Merged
Changes from all commits
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
fix(dav): Handle end of stream in File::put
If the stream is aborted and the callback wrapper returns false (or
null as it happened in some cases), we should not try to write to the
storage but abort the operation.

Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Mar 3, 2025
commit 01663e67ec3a7e669903fd0ff63eb994f3f59afa
30 changes: 13 additions & 17 deletions apps/dav/lib/Connector/Sabre/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use OC\Files\Stream\HashWrapper;
use OC\Files\View;
use OCA\DAV\AppInfo\Application;
use OCA\DAV\Connector\Sabre\Exception\BadGateway;
use OCA\DAV\Connector\Sabre\Exception\EntityTooLarge;
use OCA\DAV\Connector\Sabre\Exception\FileLocked;
use OCA\DAV\Connector\Sabre\Exception\Forbidden as DAVForbiddenException;
Expand All @@ -29,6 +28,7 @@
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\Files\Storage;
use OCP\Files\Storage\IWriteStreamStorage;
use OCP\Files\StorageNotAvailableException;
use OCP\IL10N;
use OCP\IRequest;
Expand Down Expand Up @@ -196,27 +196,23 @@
}
}

if ($partStorage->instanceOfStorage(Storage\IWriteStreamStorage::class)) {
if ($partStorage->instanceOfStorage(IWriteStreamStorage::class)) {
$isEOF = false;
$wrappedData = CallbackWrapper::wrap($data, null, null, null, null, function ($stream) use (&$isEOF) {
$isEOF = feof($stream);
});

$result = true;
$count = -1;
try {
$count = $partStorage->writeStream($internalPartPath, $wrappedData);
} catch (GenericFileException $e) {
$result = false;
} catch (BadGateway $e) {
throw $e;
}


if ($result === false) {
$result = $isEOF;
if (is_resource($wrappedData)) {
$result = feof($wrappedData);
$result = is_resource($wrappedData);
if ($result) {
$count = -1;
try {
/** @var IWriteStreamStorage $partStorage */
$count = $partStorage->writeStream($internalPartPath, $wrappedData);

Check notice

Code scanning / Psalm

PossiblyFalseArgument Note

Argument 2 of OCP\Files\Storage\IWriteStreamStorage::writeStream cannot be false, possibly resource value expected
} catch (GenericFileException) {
$result = $isEOF;
if (is_resource($wrappedData)) {
$result = feof($wrappedData);
}
}
}
} else {
Expand Down
Loading